-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #111378 - jieyouxu:local-shadows-glob-reexport, r=petro…
…chenkov Add warn-by-default lint when local binding shadows exported glob re-export item This PR introduces a warn-by-default rustc lint for when a local binding (a use statement, or a type declaration) produces a name which shadows an exported glob re-export item, causing the name from the exported glob re-export to be hidden (see #111336). ### Unresolved Questions - [x] ~~Is this approach correct? While it passes the UI tests, I'm not entirely convinced it is correct.~~ Seems to be ok now. - [x] ~~What should the lint be called / how should it be worded? I don't like calling `use x::*;` or `struct Foo;` a "local binding" but they are `NameBinding`s internally if I'm not mistaken.~~ ~~The lint is called `local_binding_shadows_glob_reexport` for now, unless a better name is suggested.~~ `hidden_glob_reexports`. Fixes #111336.
- Loading branch information
Showing
12 changed files
with
207 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// check-pass | ||
|
||
pub mod upstream_a { | ||
mod inner { | ||
pub struct Foo {} | ||
pub struct Bar {} | ||
} | ||
|
||
pub use self::inner::*; | ||
|
||
struct Foo; | ||
//~^ WARN private item shadows public glob re-export | ||
} | ||
|
||
pub mod upstream_b { | ||
mod inner { | ||
pub struct Foo {} | ||
pub struct Qux {} | ||
} | ||
|
||
mod other { | ||
pub struct Foo; | ||
} | ||
|
||
pub use self::inner::*; | ||
|
||
use self::other::Foo; | ||
//~^ WARN private item shadows public glob re-export | ||
} | ||
|
||
pub mod upstream_c { | ||
mod no_def_id { | ||
#![allow(non_camel_case_types)] | ||
pub struct u8; | ||
pub struct World; | ||
} | ||
|
||
pub use self::no_def_id::*; | ||
|
||
use std::primitive::u8; | ||
//~^ WARN private item shadows public glob re-export | ||
} | ||
|
||
// Downstream crate | ||
// mod downstream { | ||
// fn proof() { | ||
// let _ = crate::upstream_a::Foo; | ||
// let _ = crate::upstream_b::Foo; | ||
// } | ||
// } | ||
|
||
pub fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
warning: private item shadows public glob re-export | ||
--> $DIR/hidden_glob_reexports.rs:11:5 | ||
| | ||
LL | pub use self::inner::*; | ||
| -------------- the name `Foo` in the type namespace is supposed to be publicly re-exported here | ||
LL | | ||
LL | struct Foo; | ||
| ^^^^^^^^^^^ but the private item here shadows it | ||
| | ||
= note: `#[warn(hidden_glob_reexports)]` on by default | ||
|
||
warning: private item shadows public glob re-export | ||
--> $DIR/hidden_glob_reexports.rs:27:9 | ||
| | ||
LL | pub use self::inner::*; | ||
| -------------- the name `Foo` in the type namespace is supposed to be publicly re-exported here | ||
LL | | ||
LL | use self::other::Foo; | ||
| ^^^^^^^^^^^^^^^^ but the private item here shadows it | ||
|
||
warning: private item shadows public glob re-export | ||
--> $DIR/hidden_glob_reexports.rs:40:9 | ||
| | ||
LL | pub use self::no_def_id::*; | ||
| ------------------ the name `u8` in the type namespace is supposed to be publicly re-exported here | ||
LL | | ||
LL | use std::primitive::u8; | ||
| ^^^^^^^^^^^^^^^^^^ but the private item here shadows it | ||
|
||
warning: 3 warnings emitted | ||
|