rust/tests/ui/pattern/issue-52240.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

17 lines
365 B
Rust
Raw Normal View History

// 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 data in a `&` reference as mutable
*val = 9001;
}
match arr[0] {
Foo::Bar(ref s) => println!("{}", s)
}
}