File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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`.
You can’t perform that action at this time.
0 commit comments