Add test for issue #52240

Closes #52240
This commit is contained in:
memoryruins 2018-10-12 12:43:13 -04:00
parent 146fbc6a96
commit b041a79f26
2 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,16 @@
// issue-52240: Can turn immutable into mut with `ref mut`
enum Foo {
Bar(i32),
}
fn main() {
let arr = vec!(Foo::Bar(0));
if let (Some(Foo::Bar(ref mut val)), _) = (&arr.get(0), 0) {
//~^ ERROR cannot borrow field of immutable binding as mutable
*val = 9001;
}
match arr[0] {
Foo::Bar(ref s) => println!("{}", s)
}
}

View File

@ -0,0 +1,9 @@
error[E0596]: cannot borrow field of immutable binding as mutable
--> $DIR/issue-52240.rs:9:27
|
LL | if let (Some(Foo::Bar(ref mut val)), _) = (&arr.get(0), 0) {
| ^^^^^^^^^^^ cannot mutably borrow field of immutable binding
error: aborting due to previous error
For more information about this error, try `rustc --explain E0596`.