-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.I-lang-nominatedNominated for discussion during a lang team meeting.Nominated for discussion during a lang team meeting.L-dead_codeLint: dead_codeLint: dead_codeP-lang-drag-2Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang.Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant 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.Performance or correctness regression from stable to beta.
Description
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 warningDesired output
Compilation with no warningsRationale 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 warningRust 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.8Anything else?
Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=1d6bd45080b177104331d8968d8812b8
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.I-lang-nominatedNominated for discussion during a lang team meeting.Nominated for discussion during a lang team meeting.L-dead_codeLint: dead_codeLint: dead_codeP-lang-drag-2Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang.Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant 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.Performance or correctness regression from stable to beta.