Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve: Turn the "non-empty glob must import something" error into a lint #65539

Merged
merged 3 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,8 +972,9 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
if !is_prelude &&
max_vis.get() != ty::Visibility::Invisible && // Allow empty globs.
!max_vis.get().is_at_least(directive.vis.get(), &*self) {
let msg = "A non-empty glob must import something with the glob's visibility";
self.r.session.span_err(directive.span, msg);
let msg =
"glob import doesn't reexport anything because no candidate is public enough";
self.r.session.buffer_lint(UNUSED_IMPORTS, directive.id, directive.span, msg);
}
return None;
}
Expand Down
9 changes: 7 additions & 2 deletions src/test/ui/imports/reexports.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
#![warn(unused_imports)]

mod a {
fn foo() {}
mod foo {}

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

mod b {
pub fn foo() {}
mod foo { pub struct S; }
mod foo {
pub struct S;
}

pub mod a {
pub use super::foo; // This is OK since the value `foo` is visible enough.
Expand Down
28 changes: 17 additions & 11 deletions src/test/ui/imports/reexports.stderr
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
error[E0364]: `foo` is private, and cannot be re-exported
--> $DIR/reexports.rs:6:17
--> $DIR/reexports.rs:8:17
|
LL | pub use super::foo;
| ^^^^^^^^^^
|
note: consider marking `foo` as `pub` in the imported module
--> $DIR/reexports.rs:6:17
--> $DIR/reexports.rs:8:17
|
LL | pub use super::foo;
| ^^^^^^^^^^

error: A non-empty glob must import something with the glob's visibility
--> $DIR/reexports.rs:7:17
|
LL | pub use super::*;
| ^^^^^^^^

error[E0603]: module `foo` is private
--> $DIR/reexports.rs:28:15
--> $DIR/reexports.rs:33:15
|
LL | use b::a::foo::S;
| ^^^

error[E0603]: module `foo` is private
--> $DIR/reexports.rs:29:15
--> $DIR/reexports.rs:34:15
|
LL | use b::b::foo::S as T;
| ^^^

error: aborting due to 4 previous errors
warning: glob import doesn't reexport anything because no candidate is public enough
--> $DIR/reexports.rs:9:17
|
LL | pub use super::*;
| ^^^^^^^^
|
note: lint level defined here
--> $DIR/reexports.rs:1:9
|
LL | #![warn(unused_imports)]
| ^^^^^^^^^^^^^^

error: aborting due to 3 previous errors

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