-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add warn-by-default lint when local binding shadows exported glob re-export item #111378
Conversation
r? @b-naber (rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
Similarly to #107880 it's better to run this check somewhere near At that point the main binding is available as @rustbot author |
This comment was marked as resolved.
This comment was marked as resolved.
(But if that fails too we can always fall back to |
Sorry how do I check this? |
|
This comment was marked as resolved.
This comment was marked as resolved.
On which test case? |
If I change #![deny(local_binding_shadows_glob_reexport)]
pub mod upstream_a {
mod inner {
pub struct Foo {}
}
pub use self::inner::*;
struct Foo;
//~^ ERROR local binding shadows glob re-export
}
pub mod upstream_b {
mod inner {
pub struct Foo {}
}
mod other {
pub struct Foo;
}
pub use self::inner::*;
use self::other::Foo;
//~^ ERROR local binding shadows glob re-export
}
// Downstream crate
// mod downstream {
// fn proof() {
// let _ = crate::upstream_a::Foo;
// let _ = crate::upstream_b::Foo;
// }
// }
pub fn main() {} then the glob re-export items should be exported right? |
They should be exported if you add any additional non-shadowed names to them, e.g. As written in #111378 (comment) they should not be exported and should be reported as unused because they don't reexport anything at all. |
Ohh right that makes sense. Yeah the check works if I add additional non-shadowed names to @rustbot ready |
This comment has been minimized.
This comment has been minimized.
I think the lint correctly fires here? The glob re-export item |
Yes, looks exactly like a case which this lint is supposed to catch. |
In this case should I just band-aid a |
Probably rename the private |
36a2d83
to
4047827
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Not in case of tests/ui/shadowed/shadowed-trait-methods.rs |
f121097
to
b8e4a1a
Compare
This comment has been minimized.
This comment has been minimized.
r=me after allowing the lint in |
b8e4a1a
to
b960658
Compare
@rustbot ready |
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (b9c5fdc): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 645.492s -> 645.767s (0.04%) |
@jieyouxu If the order is not fixed, then it looks weird, see for example https://crater-reports.s3.amazonaws.com/pr-111505/try%23590af02d982816cfb2e4e43f8c54065e816581ce/reg/assemble-std-0.2.0/log.txt
|
Thanks for the heads up, I'll fix this tomorrow. EDIT: Currently trying to find out how I can sort them in fixed order and not span order. |
…-span-order, r=petrochenkov Adjust span labels for `HIDDEN_GLOB_REEXPORTS` Addresses rust-lang#111378 (comment). ### Before This PR The possibility that the private item comes before the glob re-export was not account for, causing the span label messages to say "but private item here shadows it" before "the name `Foo` in the type namespace is supposed to be publicly re-exported here". ### After This PR ```rust warning: private item shadows public glob re-export --> $DIR/hidden_glob_reexports.rs:9:5 | LL | struct Foo; | ^^^^^^^^^^^ the private item here shadows the name `Foo` in the type namespace ... LL | pub use self::inner::*; | -------------- but it is supposed to be publicly re-exported here | = 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 ```
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
Is this approach correct? While it passes the UI tests, I'm not entirely convinced it is correct.Seems to be ok now.What should the lint be called / how should it be worded? I don't like callinguse x::*;
orstruct Foo;
a "local binding" but they areNameBinding
s internally if I'm not mistaken.The lint is calledlocal_binding_shadows_glob_reexport
for now, unless a better name is suggested.hidden_glob_reexports
.Fixes #111336.