Skip to content

Commit 5847ea7

Browse files
committed
Customize error messages for self glob imports.
1 parent 3d041bd commit 5847ea7

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/librustc_resolve/resolve_imports.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,11 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
785785
// In this case, target_module == module_
786786
// This means we are trying to glob import a module into itself,
787787
// and it is a no-go
788-
return ResolveResult::Indeterminate;
788+
debug!("(resolving glob imports) target module is current module; giving up");
789+
return ResolveResult::Failed(Some((
790+
import_directive.span,
791+
"Cannot glob-import a module into itself.".into()
792+
)));
789793
}
790794

791795
for (ident, target_import_resolution) in import_resolutions.iter() {

src/test/compile-fail/issue-8208.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use self::*; //~ ERROR: unresolved import
11+
use self::*; //~ ERROR: unresolved import `self::*`. Cannot glob-import a module into itself.
12+
13+
mod foo {
14+
use foo::*; //~ ERROR: unresolved import `foo::*`. Cannot glob-import a module into itself.
15+
16+
mod bar {
17+
use super::bar::*;
18+
//~^ ERROR: unresolved import `super::bar::*`. Cannot glob-import a module into itself.
19+
}
20+
21+
}
1222

1323
fn main() {
1424
}

0 commit comments

Comments
 (0)