Skip to content

Rules for matching against variable unclear. #28687

Closed
@XAMPPRocky

Description

@XAMPPRocky

When you have a match statement against a variable the behaviour is unexpected.

I tried this code:

fn main() {
    let x = 'x';
    let c = 'c';
    match c {
        x => println!("Bug? {} {}", x, c),
    }

    println!("x: {}", x)
}

I expected to to see this happen:

Either get an error telling me that placing a variable won't do what I think it will do. Or allow this to happen, and allow for specific cases, as currently adding any extra arms returns a unreachable pattern error.

Instead this happened:

This compiles with no errors, or warning, and prints out:

Bug? c c
x: x

Meta

rustc --version --verbose

rustc 1.3.0 (9a92aaf19 2015-09-15)
binary: rustc
commit-hash: 9a92aaf19a64603b02b4130fe52958cc12488900
commit-date: 2015-09-15
host: x86_64-apple-darwin
release: 1.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions