Clippy warns about dead code but expect also triggers a warning

⚓ Rust    📅 2026-03-24    👤 surdeus    👁️ 2      

surdeus

I have the following weird situation:

#[expect(dead_code)]
mod unused {
    struct Unused;

    impl Clone for Unused {
        fn clone(&self) -> Self {
            todo!()
        }
    }
}

If I run cargo clippy on this I get:

warning: this lint expectation is unfulfilled
 --> src/lib.rs:1:10
  |
1 | #[expect(dead_code)]
  |          ^^^^^^^^^
  |
  = note: `#[warn(unfulfilled_lint_expectations)]` on by default

But If I remove the #[expect(dead_code)] I get:

warning: struct `Unused` is never constructed
 --> src/lib.rs:2:12
  |
2 |     struct Unused;
  |            ^^^^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

If I turn the expect into an allow there are no warnings. Also interestingly, if I remove the impl Clone for Unused the expect also works. So seems like the expect has problems if there are trait implementations for the unused type.

Is this expected behaviour or have I found a bug?

6 posts - 3 participants

Read full topic

🏷️ Rust_feed