]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-mutate-in-guard.rs
Rollup merge of #99460 - JanBeh:PR_asref_asmut_docs, r=joshtriplett
[rust.git] / src / test / ui / borrowck / borrowck-mutate-in-guard.rs
1 enum Enum<'a> {
2     A(&'a isize),
3     B(bool),
4 }
5
6 fn foo() -> isize {
7     let mut n = 42;
8     let mut x = Enum::A(&mut n);
9     match x {
10         Enum::A(_) if { x = Enum::B(false); false } => 1,
11         //~^ ERROR cannot assign `x` in match guard
12         Enum::A(_) if { let y = &mut x; *y = Enum::B(false); false } => 1,
13         //~^ ERROR cannot mutably borrow `x` in match guard
14         Enum::A(p) => *p,
15         Enum::B(_) => 2,
16     }
17 }
18
19 fn main() {
20     foo();
21 }