Skip to content

Rustc diagnostics don’t realize that assignments from a match guard can be used in the following match arms. #80954

@steffahn

Description

@steffahn
fn main() {
    let mut x = 0;
    match () {
        () if {
            x = 42;
            false
        } => {}
        _ => {
            println!("{}", x); // prints 42
        }
    }
}

(Playground)

Output:

42

Errors:

   Compiling playground v0.0.1 (/playground)
warning: value assigned to `x` is never read
 --> src/main.rs:5:13
  |
5 |             x = 42;
  |             ^
  |
  = note: `#[warn(unused_assignments)]` on by default
  = help: maybe it is overwritten before being read?

warning: 1 warning emitted

    Finished dev [unoptimized + debuginfo] target(s) in 0.74s
     Running `target/debug/playground`

@rustbot modify labels: T-compiler, A-diagnostics, A-lint, D-incorrect, C-bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-patternsRelating to patterns and pattern matchingC-bugCategory: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions