From de9413bd3403f1b95c717a839b7612e3cfe83b03 Mon Sep 17 00:00:00 2001 From: Quentin Boyer Date: Mon, 28 Oct 2019 00:57:25 +0100 Subject: [PATCH 1/3] changing non-empty glob must import something to a lint --- src/librustc_resolve/resolve_imports.rs | 5 +++-- src/test/ui/imports/reexports.rs | 9 ++++++-- src/test/ui/imports/reexports.stderr | 28 +++++++++++++++---------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 360343169bc3d..daee4d4e9b268 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -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; } diff --git a/src/test/ui/imports/reexports.rs b/src/test/ui/imports/reexports.rs index b0a591b08ac89..d76cc41be4e55 100644 --- a/src/test/ui/imports/reexports.rs +++ b/src/test/ui/imports/reexports.rs @@ -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. diff --git a/src/test/ui/imports/reexports.stderr b/src/test/ui/imports/reexports.stderr index af2c97e77b9d7..382b181f45b7b 100644 --- a/src/test/ui/imports/reexports.stderr +++ b/src/test/ui/imports/reexports.stderr @@ -1,34 +1,40 @@ error[E0364]: `foo` is private, and cannot be re-exported - --> $DIR/reexports.rs:6:17 + --> $DIR/reexports.rs:10:17 | LL | pub use super::foo; | ^^^^^^^^^^ | note: consider marking `foo` as `pub` in the imported module - --> $DIR/reexports.rs:6:17 + --> $DIR/reexports.rs:10: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:35:15 | LL | use b::a::foo::S; | ^^^ error[E0603]: module `foo` is private - --> $DIR/reexports.rs:29:15 + --> $DIR/reexports.rs:36:15 | LL | use b::b::foo::S as T; | ^^^ -error: aborting due to 4 previous errors +warning: this glob doesn't reexport anything because no canditate is public enough + --> $DIR/reexports.rs:11: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`. From 652b1bd45dfd81435b431cfe84c0f18f79c3ee7a Mon Sep 17 00:00:00 2001 From: Quentin Boyer Date: Mon, 28 Oct 2019 11:22:26 +0100 Subject: [PATCH 2/3] fix tidy --- src/librustc_resolve/resolve_imports.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index daee4d4e9b268..c387adebbf7f1 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -973,7 +973,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { max_vis.get() != ty::Visibility::Invisible && // Allow empty globs. !max_vis.get().is_at_least(directive.vis.get(), &*self) { let msg = - "glob import doesn't reexport anything because no candidate is public enough"; + "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; From ed8585ffb5a6d82cb12eff263cd0466ef3f79e36 Mon Sep 17 00:00:00 2001 From: Quentin Boyer Date: Tue, 29 Oct 2019 00:20:28 +0100 Subject: [PATCH 3/3] forgot to add the changed stderr --- src/test/ui/imports/reexports.stderr | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/ui/imports/reexports.stderr b/src/test/ui/imports/reexports.stderr index 382b181f45b7b..4388e2c276b8e 100644 --- a/src/test/ui/imports/reexports.stderr +++ b/src/test/ui/imports/reexports.stderr @@ -1,29 +1,29 @@ error[E0364]: `foo` is private, and cannot be re-exported - --> $DIR/reexports.rs:10:17 + --> $DIR/reexports.rs:8:17 | LL | pub use super::foo; | ^^^^^^^^^^ | note: consider marking `foo` as `pub` in the imported module - --> $DIR/reexports.rs:10:17 + --> $DIR/reexports.rs:8:17 | LL | pub use super::foo; | ^^^^^^^^^^ error[E0603]: module `foo` is private - --> $DIR/reexports.rs:35:15 + --> $DIR/reexports.rs:33:15 | LL | use b::a::foo::S; | ^^^ error[E0603]: module `foo` is private - --> $DIR/reexports.rs:36:15 + --> $DIR/reexports.rs:34:15 | LL | use b::b::foo::S as T; | ^^^ -warning: this glob doesn't reexport anything because no canditate is public enough - --> $DIR/reexports.rs:11:17 +warning: glob import doesn't reexport anything because no candidate is public enough + --> $DIR/reexports.rs:9:17 | LL | pub use super::*; | ^^^^^^^^