Skip to content

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

Closed

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

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 2, 2026
  2. eggyal commented on Feb 2, 2026

    @eggyal
    Contributor

    @rustbot claim

  3. theemathas commented on Feb 2, 2026

    @theemathas
    Contributor

    This emitted a warning in 1.91.0, but not 1.92.0.

  4. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    on Feb 2, 2026
  5. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Feb 2, 2026
  6. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 2, 2026
  7. mu001999 commented on Feb 2, 2026

    @mu001999
    Member

    Regression in ff6dc92, #142390

  8. apiraino commented on Feb 2, 2026

    @apiraino
    Contributor

    Assigning priority (discussion on Zulip).

    @rustbot label -I-prioritize +P-medium

  9. added and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Feb 2, 2026
  10. added a commit that references this issue on Feb 3, 2026
    b73b822
  11. added a commit that references this issue on Feb 3, 2026
    6e45695
  12. added a commit that references this issue on Feb 5, 2026
    5834cb3
  13. added a commit that references this issue on Aug 17, 2026
    66b5e06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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