Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |