-
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
Fallout from expansion of redundant import checking #121708
Comments
FYI @surechen @petrochenkov - Not trying to single you out here, but I would like your input. This is a problem I've noticed in past lint expansions, and it seems useful to focus discussion around a concrete incidence. |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as outdated.
This comment was marked as outdated.
I'm interested to see what kind of numbers crater can give us. @craterbot run name=redundant-imports start=master#6f726205a1b7992537ddec96c83f2b054b03e04f+rustflags=-Dunused-imports end=master#8b21296b5db6d5724d6b8440dcf459fa82fd88b5+rustflags=-Dunused-imports crates=top-1000 mode=check-only p=2 |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
Now I see that the only p=1 in the queue has a similar number of crates to build, so let's use the same priority. @craterbot name=redundant-imports p=1 |
📝 Configuration of the ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
Hi, thank you for starting the discussion. As a newbie to compilers, this PR was originally intended to address a smaller scope issue #117448, detecting redundant imports which should only be imported by prelude, petrochenkov provided a lot of help in the comments. I very much recognized his comment: #117772 (comment) and asked for help, so he patiently guided me to develop this PR. So my views here may not be professional enough and can only represent my own. I think Rust's powerful detection capabilities make me more confident in the code I develop. In my mind, ideally, the compiler can help me find all problems, so stricter checking of redundant imports will not cause too much trouble, but it will help me. Of course, if some lints will invalidate a large amount of existing code, it will really increase my burden, so if the community has some future policies or some measures to make the changes smoother, then I will appreciate it very much, and I will also be very happy to participate in the discussion or do some development. |
Hi, today I noticed that this is causing a lot of trouble for my crates in the Wasmi workspace, particularly the SummaryFor my crate
Many more warnings pop up, but they all are very similar to the one above. In #[cfg(not(feature = "std"))]
extern crate alloc; Thus Lint Nameunused_imports Reproducer
Version
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
My repository, which aims to support no-std when possible, explicitly imports many items within the std prelude. I effectively have to disable this lint or add tens to >100 of cfg statements, which makes no-std dev much more annoying. EDIT: I cannot disable this without disabling unused import checks entirely, which I now understand ('moving to its own lint group' wasn't immediately clear to me). This is a blocker for me to update and really unfortunate. |
I've closed some issues that duplicate this one. Issues with specific technical issues that may be fixed:
|
In general, the new lint logic does exactly the same thing as all other existing The only difference is that most other |
@surechen |
Note, that redundant imports specifically was previously reported by rustc as a part of |
The change has already reached beta, we probably want to make some decision about it until it reaches stable. |
FWIW, I assumed that prelude additions already happen at edition boundaries only. |
There's no fundamental reason they have to be. Additions to the prelude can't create conflicts, because they'll be shadowed by any declarations by the user. (There are exceptions to that, such as traits, which can create ambiguities, so we only add traits at edition boundaries.) |
@petrochenkov wrote:
Should we consider a beta revert to give time to evaluate this? |
Commenting out the line that emits the lint is trivial. |
I legitimately believe it should be moved to clippy, arguably even pedantic. I do say this as someone not involved with Rust development however, solely as a strongly opinionated user. Apologies if I'm being too noisy on this. |
@petrochenkov I think the right fix is either going to be to keep it but under a different name and allow-by-default, or revert it entirely. Either way, I don't think we should keep it under the existing warn-by-default lint. (I know @tmandry is working on the more general policy questions here.) Could you please make the one-line change so that we have time to evaluate this? (I'd appreciate a second from @rust-lang/lang for confirmation.) Thank you. |
Hello, I have talked with @petrochenkov and I will submit a PR to beta to block it through comments first. |
…lob, r=petrochenkov Silence `unused_imports` for redundant imports Quick fix for rust-lang#121708 (comment) r? `@petrochenkov` cc `@joshtriplett` I think this is right, would like confirmation. I also think it's weird that we're using `=` to assign to `is_redundant` but using `per_ns` for the actual spans. Seems like this could be weirdly order dependent, but that's unrelated to this change.
Rollup merge of rust-lang#123744 - compiler-errors:redundant-due-to-glob, r=petrochenkov Silence `unused_imports` for redundant imports Quick fix for rust-lang#121708 (comment) r? `@petrochenkov` cc `@joshtriplett` I think this is right, would like confirmation. I also think it's weird that we're using `=` to assign to `is_redundant` but using `per_ns` for the actual spans. Seems like this could be weirdly order dependent, but that's unrelated to this change.
FWIW I was very happy to finally have rustc detect a whole bunch of unnecessary imports for me. :) But I also don't work on no_std code, let alone "conditionally no_std". I just wanted to say this to make this issue not just focus on the negative consequences of the lint expansion. |
I've noticed there is a lot of fallout from the changes in #117772 expanding redundant import checking. See discussion and backlinks on that issue as well as #118692 for some evidence.
I have a theory that redundant imports should be split out into their own lint group (this was discussed in the past), and that in the future as a matter of policy, disruptive expansions like this should come with a machine-applicable fix to make rollout smoother.
For now, I'm opening this issue to collect data and feedback that I want to use to inform future policy discussions around lint expansions.
The text was updated successfully, but these errors were encountered: