-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 useless_anonymous_reexport
lint
#109003
Add useless_anonymous_reexport
lint
#109003
Conversation
r? @TaKO8Ki (rustbot has picked a reviewer for you, use r? to override) |
fd77cfe
to
0884258
Compare
This lint would probably be easier to implement in |
@cjgillot It doesn't seem that they are considered as potentially unused since they don't appear in |
|
So unless I missed something, |
0884258
to
6d2b775
Compare
Greatly improved the detection of re-export following suggestion. |
☔ The latest upstream changes (presumably #108682) made this pull request unmergeable. Please resolve the merge conflicts. |
6d2b775
to
fcadc03
Compare
pub use self::my_mod::Foo as _; | ||
pub use self::my_mod::TyFoo as _; | ||
pub use self::my_mod::Bar as _; //~ ERROR | ||
pub use self::my_mod::TyBar as _; //~ ERROR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we suggest to remove it?
Could you add tests with nested uses:
pub use self::my_mod::{Bar as _};
pub use self::my_mod::{Bar as _, Foo as _};
pub use self::my_mod::{Bar as _, TyBar as _};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding tests with nested uses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we suggest to remove it?
I'm not sure. If you prefer I add this suggestion, I can.
e89c425
to
9272b69
Compare
9272b69
to
7b0fa08
Compare
Added what was missing. |
@bors r+ |
Rollup of 10 pull requests Successful merges: - rust-lang#104100 (Allow using `Range` as an `Iterator` in const contexts. ) - rust-lang#105793 (Add note for mismatched types because of circular dependencies) - rust-lang#108798 (move default backtrace setting to sys) - rust-lang#108829 (Use Edition 2021 :pat in matches macro) - rust-lang#108973 (Beautify pin! docs) - rust-lang#109003 (Add `useless_anonymous_reexport` lint) - rust-lang#109022 (read_buf_exact: on error, all read bytes are appended to the buffer) - rust-lang#109212 (fix: don't suggest similar method when unstable) - rust-lang#109243 (The name of NativeLib will be presented) - rust-lang#109324 (Implement FixedSizeEncoding for UnusedGenericParams.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
if let ItemKind::Use(path, kind) = item.kind && | ||
!matches!(kind, UseKind::Glob) && | ||
item.ident.name == kw::Underscore && | ||
// We only want re-exports. If it's just a `use X;`, then we ignore it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this important?
A private use some::Struct as _
is equally useless.
The original suggestion from @cjgillot to use UnusedImportCheckVisitor
and report this early looks like the right direction.
This case doesn't need a separate lint, existing unused_imports
should be perfectly fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lint multiplies entities without necessity, I think it is better to remove it before it hit stable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I noticed this while auditing uses of imports in HIR for #109176 (comment).)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lint multiplies entities without necessity
How so?
I think it is better to remove it before it hit stable.
Replaced, sure. Otherwise please don't remove it altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How so?
Is there any scenario when you'd want to enable/deny reporting this case specifically, separately from other unused imports? I don't think so.
Replaced, sure. Otherwise please don't remove it altogether.
Yeah, I mean merge into unused_imports
, not remove outright.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Also, the lint name doesn't match conventions.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I see. Well, since both you and cjgillot think so, I'll move it into unused imports.
…rt-check, r=petrochenkov Move useless_anynous_reexport lint into unused_imports As mentioned in rust-lang#109003, this check should have been merged with `unused_imports` in the start. r? `@petrochenkov`
… r=petrochenkov Move useless_anynous_reexport lint into unused_imports As mentioned in rust-lang/rust#109003, this check should have been merged with `unused_imports` in the start. r? `@petrochenkov`
This is a follow-up of #108936. We once again show all anonymous re-exports in rustdoc, however we also wanted to add a lint to let users know that it very likely doesn't have the effect they think it has.