You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
unused_imports redundant import check false positive with dev-dependency #121684
use bitcoin::secp256k1;pubstructThing(pub secp256k1::SecretKey);fnmain(){println!("Hello, world!");}
If you compile this project with a recent nightly you will see the warning
Compiling unused_import_bug-2024-02 v0.1.0 (/store/home/apoelstra/code/tmp/unused_import_bug-2024-02)
warning: the item `secp256k1` is imported redundantly
--> src/main.rs:2:5
|
2 | use bitcoin::secp256k1;
| ^^^^^^^^^^^^^^^^^^ the item `secp256k1` is already defined here
|
= note: `#[warn(unused_imports)]` on by default
This warning should not show up, and if it must show up, it should say where the compiler thinks the "redundant import" actually is. Because there is only a single import.
If you comment out the [dev-dependencies] part of Cargo.toml the error goes away.
Ok, what I think is going on is that when you run cargo test, all the dev-dependencies are implicitly imported, meaning that your necessary-for-cargo build imports become redundant.
If this is expected behavior then the error message needs to be much clearer.
Ok, I can mostly patch this by sticking #[cfg(not(test))] onto all of my imports, but for examples this doesn't work. It seems like examples pull in dev-dependencies but do not have cfg(test) set.
I can remove the import entirely, but then I am left with "example" code which does not actually compile outside of an example/ directory.
Activity
apoelstra commentedon Feb 27, 2024
Ok, what I think is going on is that when you run
cargo test, all the dev-dependencies are implicitly imported, meaning that your necessary-for-cargo buildimports become redundant.If this is expected behavior then the error message needs to be much clearer.
apoelstra commentedon Feb 27, 2024
Ok, I can mostly patch this by sticking
#[cfg(not(test))]onto all of my imports, but for examples this doesn't work. It seems like examples pull in dev-dependencies but do not havecfg(test)set.I can remove the import entirely, but then I am left with "example" code which does not actually compile outside of an example/ directory.
ci: screw up imports for rust-lang/rust#121684
ci: screw up imports for rust-lang/rust#121684
ci: screw up imports for rust-lang/rust#121684
Merge #645: remove sketchy `LikelyFalse` error
petrochenkov commentedon Mar 2, 2024
All
unusedlints work aftercfgs are expanded, this one is no different, so I'm going to close the issue.The recent extension of
unused_importshad some large effect on users in general, that is discussed in #121708 which is still open.ci: screw up imports for rust-lang/rust#121684
Merge rust-bitcoin/rust-miniscript#645: remove sketchy `LikelyFalse` …
Drop obsolete unused-import workaround
Drop obsolete unused-import workaround
Drop obsolete unused-import workaround
Merge #1001: Drop obsolete unused-import workaround