Skip to content

Missing "unused variable" warning when using a match guard #151983

@nstoddard

Description

@nstoddard

I tried this code:

fn main() {
    match Some(42) {
        Some(unused) if true => (),
        _ => (),
    }
}

I expected to see this happen: the compiler should warn that unused is unused.

Instead, this happened: the code compiles without any warnings, unless the if true part is removed.

Meta

rustc --version --verbose:

rustc 1.93.0 (254b59607 2026-01-19)
binary: rustc
commit-hash: 254b59607d4417e9dffbc307138ae5c86280fe4c
commit-date: 2026-01-19
host: x86_64-unknown-linux-gnu
release: 1.93.0
LLVM version: 21.1.8

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.L-unused_variablesLint: unused_variablesP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions