Skip to content

Commit

Permalink
Add test for issue #52240
Browse files Browse the repository at this point in the history
Closes #52240
  • Loading branch information
memoryruins committed Oct 12, 2018
1 parent 146fbc6 commit b041a79
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/test/ui/issues/issue-52240.rs
@@ -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)
}
}
9 changes: 9 additions & 0 deletions src/test/ui/issues/issue-52240.stderr
@@ -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`.

0 comments on commit b041a79

Please sign in to comment.