Skip to content

Commit 4a4fbac

Browse files
committed
Auto merge of #57160 - petrochenkov:impice2, r=estebank
resolve: Fix an ICE in import validation Fixes ICE reported in the comment #56596 (comment)
2 parents 43d26b1 + ce73bc7 commit 4a4fbac

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

src/librustc_resolve/resolve_imports.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,25 @@ impl<'a> Resolver<'a> {
223223
}
224224

225225
let check_usable = |this: &mut Self, binding: &'a NameBinding<'a>| {
226-
if let Some(blacklisted_binding) = this.blacklisted_binding {
227-
if ptr::eq(binding, blacklisted_binding) {
228-
return Err((Determined, Weak::No));
229-
}
230-
}
231226
// `extern crate` are always usable for backwards compatibility, see issue #37020,
232227
// remove this together with `PUB_USE_OF_PRIVATE_EXTERN_CRATE`.
233228
let usable = this.is_accessible(binding.vis) || binding.is_extern_crate();
234229
if usable { Ok(binding) } else { Err((Determined, Weak::No)) }
235230
};
236231

237232
if record_used {
238-
return resolution.binding.ok_or((Determined, Weak::No)).and_then(|binding| {
233+
return resolution.binding.and_then(|binding| {
234+
// If the primary binding is blacklisted, search further and return the shadowed
235+
// glob binding if it exists. What we really want here is having two separate
236+
// scopes in a module - one for non-globs and one for globs, but until that's done
237+
// use this hack to avoid inconsistent resolution ICEs during import validation.
238+
if let Some(blacklisted_binding) = self.blacklisted_binding {
239+
if ptr::eq(binding, blacklisted_binding) {
240+
return resolution.shadowed_glob;
241+
}
242+
}
243+
Some(binding)
244+
}).ok_or((Determined, Weak::No)).and_then(|binding| {
239245
if self.last_import_segment && check_usable(self, binding).is_err() {
240246
Err((Determined, Weak::No))
241247
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Nothing here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// edition:2018
2+
// compile-flags: --extern issue_56596
3+
// aux-build:issue-56596.rs
4+
5+
#![feature(uniform_paths)]
6+
7+
mod m {
8+
pub mod issue_56596 {}
9+
}
10+
11+
use m::*;
12+
use issue_56596; //~ ERROR `issue_56596` is ambiguous
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0659]: `issue_56596` is ambiguous (name vs any other name during import resolution)
2+
--> $DIR/issue-56596.rs:12:5
3+
|
4+
LL | use issue_56596; //~ ERROR `issue_56596` is ambiguous
5+
| ^^^^^^^^^^^ ambiguous name
6+
|
7+
= note: `issue_56596` could refer to an extern crate passed with `--extern`
8+
= help: use `::issue_56596` to refer to this extern crate unambiguously
9+
note: `issue_56596` could also refer to the module imported here
10+
--> $DIR/issue-56596.rs:11:5
11+
|
12+
LL | use m::*;
13+
| ^^^^
14+
= help: use `crate::issue_56596` to refer to this module unambiguously
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0659`.

0 commit comments

Comments
 (0)