mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 06:51:58 +00:00
parent
146fbc6a96
commit
b041a79f26
16
src/test/ui/issues/issue-52240.rs
Normal file
16
src/test/ui/issues/issue-52240.rs
Normal 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)
|
||||
}
|
||||
}
|
9
src/test/ui/issues/issue-52240.stderr
Normal file
9
src/test/ui/issues/issue-52240.stderr
Normal 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`.
|
Loading…
Reference in New Issue
Block a user