Skip to content

match binding is unexpectedly mutable #12452

@lilyball

Description

@lilyball

Submitted from reddit. The following code works, and it shouldn't:

enum Foo {
    Bar(int)
}

fn main() {
    let bar = Bar(1);
    match bar {
        Bar(x) => { // shouldn't x be immutable?
            println!("x = {}" ,x);
            x += 1;
            println!("x = {}" ,x);
        }
    }
}

This prints

x = 1
x = 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions