Skip to content

Commit b041a79

Browse files
committed
Add test for issue #52240
Closes #52240
1 parent 146fbc6 commit b041a79

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Diff for: src/test/ui/issues/issue-52240.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// issue-52240: Can turn immutable into mut with `ref mut`
2+
3+
enum Foo {
4+
Bar(i32),
5+
}
6+
7+
fn main() {
8+
let arr = vec!(Foo::Bar(0));
9+
if let (Some(Foo::Bar(ref mut val)), _) = (&arr.get(0), 0) {
10+
//~^ ERROR cannot borrow field of immutable binding as mutable
11+
*val = 9001;
12+
}
13+
match arr[0] {
14+
Foo::Bar(ref s) => println!("{}", s)
15+
}
16+
}

Diff for: src/test/ui/issues/issue-52240.stderr

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

0 commit comments

Comments
 (0)