Skip to content

Commit 98e435e

Browse files
committed
resolve: Fix an ICE in import validation
1 parent 063553f commit 98e435e

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

src/librustc_resolve/resolve_imports.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,25 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
228228
}
229229

230230
let check_usable = |this: &mut Self, binding: &'a NameBinding<'a>| {
231-
if let Some(blacklisted_binding) = this.blacklisted_binding {
232-
if ptr::eq(binding, blacklisted_binding) {
233-
return Err((Determined, Weak::No));
234-
}
235-
}
236231
// `extern crate` are always usable for backwards compatibility, see issue #37020,
237232
// remove this together with `PUB_USE_OF_PRIVATE_EXTERN_CRATE`.
238233
let usable = this.is_accessible(binding.vis) || binding.is_extern_crate();
239234
if usable { Ok(binding) } else { Err((Determined, Weak::No)) }
240235
};
241236

242237
if record_used {
243-
return resolution.binding.ok_or((Determined, Weak::No)).and_then(|binding| {
238+
return resolution.binding.and_then(|binding| {
239+
// If the primary binding is blacklisted, search further and return the shadowed
240+
// glob binding if it exists. What we really want here is having two separate
241+
// scopes in a module - one for non-globs and one for globs, but until that's done
242+
// use this hack to avoid inconsistent resolution ICEs during import validation.
243+
if let Some(blacklisted_binding) = self.blacklisted_binding {
244+
if ptr::eq(binding, blacklisted_binding) {
245+
return resolution.shadowed_glob;
246+
}
247+
}
248+
Some(binding)
249+
}).ok_or((Determined, Weak::No)).and_then(|binding| {
244250
if self.last_import_segment && check_usable(self, binding).is_err() {
245251
Err((Determined, Weak::No))
246252
} else {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Nothing here
Lines changed: 14 additions & 0 deletions
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() {}
Lines changed: 18 additions & 0 deletions
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)