Skip to content

Binding subpattern with @ allows for illegal mutation #14587

Closed
@Marwes

Description

@Marwes
fn main() {
    match &mut Some(1) {
        ref mut z @ &Some(ref a) => {
            **z = None;
            println!("{}", *a);
        }
        _ => ()
    }
}

This code compiles even though it should be rejected since writing to z invalidates the a variable.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions