]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-mutate-in-guard.rs
Unit test from #57866.
[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 in a pattern guard
12         Enum::A(_) if { let y = &mut x; *y = Enum::B(false); false } => 1,
13         //~^ ERROR cannot mutably borrow in a pattern guard
14         //~^^ ERROR cannot assign in a pattern guard
15         Enum::A(p) => *p,
16         Enum::B(_) => 2,
17     }
18 }
19
20 fn main() {
21     foo();
22 }