Skip to content

Commit de9413b

Browse files
committed
changing non-empty glob must import something to a lint
1 parent e369d87 commit de9413b

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

src/librustc_resolve/resolve_imports.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,9 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
972972
if !is_prelude &&
973973
max_vis.get() != ty::Visibility::Invisible && // Allow empty globs.
974974
!max_vis.get().is_at_least(directive.vis.get(), &*self) {
975-
let msg = "A non-empty glob must import something with the glob's visibility";
976-
self.r.session.span_err(directive.span, msg);
975+
let msg =
976+
"glob import doesn't reexport anything because no candidate is public enough";
977+
self.r.session.buffer_lint(UNUSED_IMPORTS, directive.id, directive.span, msg);
977978
}
978979
return None;
979980
}

src/test/ui/imports/reexports.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1+
#![warn(unused_imports)]
2+
13
mod a {
24
fn foo() {}
35
mod foo {}
46

57
mod a {
68
pub use super::foo; //~ ERROR cannot be re-exported
7-
pub use super::*; //~ ERROR must import something with the glob's visibility
9+
pub use super::*;
10+
//~^ WARNING glob import doesn't reexport anything because no candidate is public enough
811
}
912
}
1013

1114
mod b {
1215
pub fn foo() {}
13-
mod foo { pub struct S; }
16+
mod foo {
17+
pub struct S;
18+
}
1419

1520
pub mod a {
1621
pub use super::foo; // This is OK since the value `foo` is visible enough.

src/test/ui/imports/reexports.stderr

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
11
error[E0364]: `foo` is private, and cannot be re-exported
2-
--> $DIR/reexports.rs:6:17
2+
--> $DIR/reexports.rs:10:17
33
|
44
LL | pub use super::foo;
55
| ^^^^^^^^^^
66
|
77
note: consider marking `foo` as `pub` in the imported module
8-
--> $DIR/reexports.rs:6:17
8+
--> $DIR/reexports.rs:10:17
99
|
1010
LL | pub use super::foo;
1111
| ^^^^^^^^^^
1212

13-
error: A non-empty glob must import something with the glob's visibility
14-
--> $DIR/reexports.rs:7:17
15-
|
16-
LL | pub use super::*;
17-
| ^^^^^^^^
18-
1913
error[E0603]: module `foo` is private
20-
--> $DIR/reexports.rs:28:15
14+
--> $DIR/reexports.rs:35:15
2115
|
2216
LL | use b::a::foo::S;
2317
| ^^^
2418

2519
error[E0603]: module `foo` is private
26-
--> $DIR/reexports.rs:29:15
20+
--> $DIR/reexports.rs:36:15
2721
|
2822
LL | use b::b::foo::S as T;
2923
| ^^^
3024

31-
error: aborting due to 4 previous errors
25+
warning: this glob doesn't reexport anything because no canditate is public enough
26+
--> $DIR/reexports.rs:11:17
27+
|
28+
LL | pub use super::*;
29+
| ^^^^^^^^
30+
|
31+
note: lint level defined here
32+
--> $DIR/reexports.rs:1:9
33+
|
34+
LL | #![warn(unused_imports)]
35+
| ^^^^^^^^^^^^^^
36+
37+
error: aborting due to 3 previous errors
3238

3339
Some errors have detailed explanations: E0364, E0603.
3440
For more information about an error, try `rustc --explain E0364`.

0 commit comments

Comments
 (0)