-
Notifications
You must be signed in to change notification settings - Fork 13k
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 |
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. |
rust-lang/rust#121708 (comment) points out that new linting scenarios have been moved into a separate lint. Thanks to this, we no longer need to globally disable this lint in Chromium (some narrower exclusions still need to apply). Bug: chromium:326247202 Change-Id: I8b919d0d04eb057e351d6a21bdb059902d0fe753 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6130365 Reviewed-by: Nabil Wadih <[email protected]> Commit-Queue: Łukasz Anforowicz <[email protected]> Reviewed-by: Nico Weber <[email protected]> Cr-Commit-Position: refs/heads/main@{#1401585}
This warning is now enabled for all chromium code, and it has been triggered with some of the zcash code. Additionally, this change has to correct a lot of the formatting for that file, which seems to have changed considerably. Chromium change: https://chromium.googlesource.com/chromium/src/+/6f81efe9a3d000dcbc952d6f14284c8178a960ec commit 6f81efe9a3d000dcbc952d6f14284c8178a960ec Author: Lukasz Anforowicz <[email protected]> Date: Thu Jan 2 13:45:03 2025 -0800 Stop globally disabling `unused-imports` lint when compiling Rust. rust-lang/rust#121708 (comment) points out that new linting scenarios have been moved into a separate lint. Thanks to this, we no longer need to globally disable this lint in Chromium (some narrower exclusions still need to apply). Bug: chromium:326247202
error: unused import: `Hashable` --> ../../brave/components/brave_wallet/browser/zcash/rust/librustzcash/src/zcash_primitives/src\merkle_tree.rs:7:14 | 7 | Address, Hashable, Level, MerklePath, Position, | ^^^^^^^^ | = note: `-D unused-imports` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unused_imports)]` error: unused import: `Write` --> ../../brave/components/brave_wallet/browser/zcash/rust/librustzcash/src/zcash_primitives/src\transaction\mod.rs:4:27 | 4 | use std::io::{self, Read, Write}; | ^^^^^ Chromium change: https://chromium.googlesource.com/chromium/src/+/6f81efe9a3d000dcbc952d6f14284c8178a960ec commit 6f81efe9a3d000dcbc952d6f14284c8178a960ec Author: Lukasz Anforowicz <[email protected]> Date: Thu Jan 2 13:45:03 2025 -0800 Stop globally disabling `unused-imports` lint when compiling Rust. rust-lang/rust#121708 (comment) points out that new linting scenarios have been moved into a separate lint. Thanks to this, we no longer need to globally disable this lint in Chromium (some narrower exclusions still need to apply). Bug: chromium:326247202
This warning is now enabled for all chromium code, and it has been triggered with some of the zcash code. Additionally, this change has to correct a lot of the formatting for that file, which seems to have changed considerably. Chromium change: https://chromium.googlesource.com/chromium/src/+/6f81efe9a3d000dcbc952d6f14284c8178a960ec commit 6f81efe9a3d000dcbc952d6f14284c8178a960ec Author: Lukasz Anforowicz <[email protected]> Date: Thu Jan 2 13:45:03 2025 -0800 Stop globally disabling `unused-imports` lint when compiling Rust. rust-lang/rust#121708 (comment) points out that new linting scenarios have been moved into a separate lint. Thanks to this, we no longer need to globally disable this lint in Chromium (some narrower exclusions still need to apply). Bug: chromium:326247202
error: unused import: `Hashable` --> ../../brave/components/brave_wallet/browser/zcash/rust/librustzcash/src/zcash_primitives/src\merkle_tree.rs:7:14 | 7 | Address, Hashable, Level, MerklePath, Position, | ^^^^^^^^ | = note: `-D unused-imports` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unused_imports)]` error: unused import: `Write` --> ../../brave/components/brave_wallet/browser/zcash/rust/librustzcash/src/zcash_primitives/src\transaction\mod.rs:4:27 | 4 | use std::io::{self, Read, Write}; | ^^^^^ Chromium change: https://chromium.googlesource.com/chromium/src/+/6f81efe9a3d000dcbc952d6f14284c8178a960ec commit 6f81efe9a3d000dcbc952d6f14284c8178a960ec Author: Lukasz Anforowicz <[email protected]> Date: Thu Jan 2 13:45:03 2025 -0800 Stop globally disabling `unused-imports` lint when compiling Rust. rust-lang/rust#121708 (comment) points out that new linting scenarios have been moved into a separate lint. Thanks to this, we no longer need to globally disable this lint in Chromium (some narrower exclusions still need to apply). Bug: chromium:326247202
This warning is now enabled for all chromium code, and it has been triggered with some of the zcash code. Additionally, this change has to correct a lot of the formatting for that file, which seems to have changed considerably. Chromium change: https://chromium.googlesource.com/chromium/src/+/6f81efe9a3d000dcbc952d6f14284c8178a960ec commit 6f81efe9a3d000dcbc952d6f14284c8178a960ec Author: Lukasz Anforowicz <[email protected]> Date: Thu Jan 2 13:45:03 2025 -0800 Stop globally disabling `unused-imports` lint when compiling Rust. rust-lang/rust#121708 (comment) points out that new linting scenarios have been moved into a separate lint. Thanks to this, we no longer need to globally disable this lint in Chromium (some narrower exclusions still need to apply). Bug: chromium:326247202
error: unused import: `Hashable` --> ../../brave/components/brave_wallet/browser/zcash/rust/librustzcash/src/zcash_primitives/src\merkle_tree.rs:7:14 | 7 | Address, Hashable, Level, MerklePath, Position, | ^^^^^^^^ | = note: `-D unused-imports` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unused_imports)]` error: unused import: `Write` --> ../../brave/components/brave_wallet/browser/zcash/rust/librustzcash/src/zcash_primitives/src\transaction\mod.rs:4:27 | 4 | use std::io::{self, Read, Write}; | ^^^^^ Chromium change: https://chromium.googlesource.com/chromium/src/+/6f81efe9a3d000dcbc952d6f14284c8178a960ec commit 6f81efe9a3d000dcbc952d6f14284c8178a960ec Author: Lukasz Anforowicz <[email protected]> Date: Thu Jan 2 13:45:03 2025 -0800 Stop globally disabling `unused-imports` lint when compiling Rust. rust-lang/rust#121708 (comment) points out that new linting scenarios have been moved into a separate lint. Thanks to this, we no longer need to globally disable this lint in Chromium (some narrower exclusions still need to apply). Bug: chromium:326247202
This warning is now enabled for all chromium code, and it has been triggered with some of the zcash code. Additionally, this change has to correct a lot of the formatting for that file, which seems to have changed considerably. Chromium change: https://chromium.googlesource.com/chromium/src/+/6f81efe9a3d000dcbc952d6f14284c8178a960ec commit 6f81efe9a3d000dcbc952d6f14284c8178a960ec Author: Lukasz Anforowicz <[email protected]> Date: Thu Jan 2 13:45:03 2025 -0800 Stop globally disabling `unused-imports` lint when compiling Rust. rust-lang/rust#121708 (comment) points out that new linting scenarios have been moved into a separate lint. Thanks to this, we no longer need to globally disable this lint in Chromium (some narrower exclusions still need to apply). Bug: chromium:326247202
error: unused import: `Hashable` --> ../../brave/components/brave_wallet/browser/zcash/rust/librustzcash/src/zcash_primitives/src\merkle_tree.rs:7:14 | 7 | Address, Hashable, Level, MerklePath, Position, | ^^^^^^^^ | = note: `-D unused-imports` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unused_imports)]` error: unused import: `Write` --> ../../brave/components/brave_wallet/browser/zcash/rust/librustzcash/src/zcash_primitives/src\transaction\mod.rs:4:27 | 4 | use std::io::{self, Read, Write}; | ^^^^^ Chromium change: https://chromium.googlesource.com/chromium/src/+/6f81efe9a3d000dcbc952d6f14284c8178a960ec commit 6f81efe9a3d000dcbc952d6f14284c8178a960ec Author: Lukasz Anforowicz <[email protected]> Date: Thu Jan 2 13:45:03 2025 -0800 Stop globally disabling `unused-imports` lint when compiling Rust. rust-lang/rust#121708 (comment) points out that new linting scenarios have been moved into a separate lint. Thanks to this, we no longer need to globally disable this lint in Chromium (some narrower exclusions still need to apply). Bug: chromium:326247202
This warning is now enabled for all chromium code, and it has been triggered with some of the zcash code. Additionally, this change has to correct a lot of the formatting for that file, which seems to have changed considerably. Chromium change: https://chromium.googlesource.com/chromium/src/+/6f81efe9a3d000dcbc952d6f14284c8178a960ec commit 6f81efe9a3d000dcbc952d6f14284c8178a960ec Author: Lukasz Anforowicz <[email protected]> Date: Thu Jan 2 13:45:03 2025 -0800 Stop globally disabling `unused-imports` lint when compiling Rust. rust-lang/rust#121708 (comment) points out that new linting scenarios have been moved into a separate lint. Thanks to this, we no longer need to globally disable this lint in Chromium (some narrower exclusions still need to apply). Bug: chromium:326247202
error: unused import: `Hashable` --> ../../brave/components/brave_wallet/browser/zcash/rust/librustzcash/src/zcash_primitives/src\merkle_tree.rs:7:14 | 7 | Address, Hashable, Level, MerklePath, Position, | ^^^^^^^^ | = note: `-D unused-imports` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unused_imports)]` error: unused import: `Write` --> ../../brave/components/brave_wallet/browser/zcash/rust/librustzcash/src/zcash_primitives/src\transaction\mod.rs:4:27 | 4 | use std::io::{self, Read, Write}; | ^^^^^ Chromium change: https://chromium.googlesource.com/chromium/src/+/6f81efe9a3d000dcbc952d6f14284c8178a960ec commit 6f81efe9a3d000dcbc952d6f14284c8178a960ec Author: Lukasz Anforowicz <[email protected]> Date: Thu Jan 2 13:45:03 2025 -0800 Stop globally disabling `unused-imports` lint when compiling Rust. rust-lang/rust#121708 (comment) points out that new linting scenarios have been moved into a separate lint. Thanks to this, we no longer need to globally disable this lint in Chromium (some narrower exclusions still need to apply). Bug: chromium:326247202
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: