Skip to content

#[expect(unused)] false-positive unfulfilled_lint_expectations warning on implemented but unused traits #152370

@yuriks

Description

@yuriks

Code

#[expect(unused)]
trait UnusedTrait {}

struct UsedStruct(u32);

impl UnusedTrait for UsedStruct {}

fn main() {
    let x = UsedStruct(12);
    println!("Hello World! {}", x.0);
}

Current output

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

warning: `playground` (bin "playground") generated 1 warning

Desired output

Compilation with no warnings

Rationale and extra context

The code above throws an unfulfilled_lint_expectations lint even though, if it were removed, the compiler would emit a dead_code lint for the trait.
This only happens when the trait is implemented for some type but ultimately still ends up unused. If there are no implementations at all then expect suppresses the lint correctly without a warning.

Other cases

// If `#[expect(unused)]` is commented out:
warning: trait `UnusedTrait` is never used
 --> src/main.rs:2:7
  |
2 | trait UnusedTrait {}
  |       ^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: `playground` (bin "playground") generated 1 warning

Rust Version

rustc 1.94.0-beta.2 (23a44d3c7 2026-01-25)
binary: rustc
commit-hash: 23a44d3c70448c08dc6a2fc13c1afceab49f2bb9
commit-date: 2026-01-25
host: x86_64-pc-windows-msvc
release: 1.94.0-beta.2
LLVM version: 21.1.8

Anything else?

Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=1d6bd45080b177104331d8968d8812b8

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.I-lang-nominatedNominated for discussion during a lang team meeting.L-dead_codeLint: dead_codeP-lang-drag-2Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions