unused_import indicates a very perplexing span on nightly-2023-11-30
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
Cargo.toml
[package]
name = "unused_import"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
[features]
feature_1 = []
feature_2 = []
lib.rs:
pub mod seed;
#[cfg(feature = "feature_1")]
mod feature_1;
#[cfg(feature = "feature_1")]
pub use feature_1::*;
#[cfg(feature = "feature_2")]
mod feature_2;
#[cfg(feature = "feature_2")]
pub use feature_2::*;
seed.rs:
pub struct Seed(u128);
feature_1.rs:
pub use super::seed::Seed;
feature_2.rs:
pub use crate::seed::Seed;
Current output
cargo +nightly-2023-11-30 build --features=feature_1,feature_2
Compiling unused_import_false_positive v0.1.0 (/home/arthur/Documents/zama/code/unused_import_false_positive)
warning: unused import: `crate::seed::Seed`
--> src/feature_2.rs:1:9
|
1 | pub use crate::seed::Seed;
| ^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused import: `feature_2::*`
--> src/lib.rs:11:9
|
11 | pub use feature_2::*;
| ^^^^^^^^^^^^
warning: `unused_import_false_positive` (lib) generated 2 warnings (run `cargo fix --lib -p unused_import_false_positive` to apply 2 suggestions)
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Desired output
cargo +nightly-2023-11-30 build --features=feature_1,feature_2
Compiling unused_import_false_positive v0.1.0 (/home/arthur/Documents/zama/code/unused_import_false_positive)
warning: unused import: `crate::seed::Seed`
--> src/feature_2.rs:1:9
|
1 | pub use crate::seed::Seed;
| ^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused import: `feature_2::*`
--> src/lib.rs:11:9
|
11 | pub use feature_2::*;
| ^^^^^^^^^^^^
Because `Seed` is already publicly exported here:
--> src/lib.rs:11:9
|
6 | pub use feature_1::*;
| ^^^^^^^^^^^^
warning: `unused_import_false_positive` (lib) generated 2 warnings (run `cargo fix --lib -p unused_import_false_positive` to apply 2 suggestions)
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Rationale and extra context
Not sure why multiple exports of the same type have been deemed bad or worth a lint (or maybe it's a side effect of changes on the unused_import detection) but I was in a larger project where I could not figure out why this started popping up when updating to the latest nightly.
Also for whatever reason on the bigger project I did not get the lib.rs reference, here I guess the project is small enough that the compiler manages to give the information.
Other cases
No response
Anything else?
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report with the Cargo.toml feature definitions and lib.rs, seed.rs, feature_1.rs, and feature_2.rs examples using the shown nightly build command. Start by examining the unused_import diagnostics for the two feature re-exports and determine whether the duplicate public export is expected. Done means the behavior is clarified and covered by a regression case if a compiler change is needed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100