Skip to content

unused_imports redundant import check false positive with dev-dependency #121684

Closed
@apoelstra

Description

@apoelstra

I tried this code:

Cargo.toml

[package]
name = "unused_import_bug-2024-02"
version = "0.1.0"
edition = "2021"

[features]
default = ["std"]
std = ["bitcoin/std", "bitcoin/secp-recovery" ]

[dependencies]
bitcoin = { version = "0.31.0", default-features = false }

[dev-dependencies]
secp256k1 = {version = "0.28.0", features = ["rand-std"]}

src/main.rs

use bitcoin::secp256k1;

pub struct Thing(pub secp256k1::SecretKey);

fn main() {
    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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions