]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-mutate-in-guard.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / borrowck-mutate-in-guard.rs
1 #![feature(if_let_guard)]
2
3 enum Enum<'a> {
4     A(&'a isize),
5     B(bool),
6 }
7
8 fn if_guard() -> isize {
9     let mut n = 42;
10     let mut x = Enum::A(&mut n);
11     match x {
12         Enum::A(_) if { x = Enum::B(false); false } => 1,
13         //~^ ERROR cannot assign `x` in match guard
14         Enum::A(_) if { let y = &mut x; *y = Enum::B(false); false } => 1,
15         //~^ ERROR cannot mutably borrow `x` in match guard
16         Enum::A(p) => *p,
17         Enum::B(_) => 2,
18     }
19 }
20
21 fn if_let_guard() -> isize {
22     let mut n = 42;
23     let mut x = Enum::A(&mut n);
24     match x {
25         Enum::A(_) if let Some(()) = { x = Enum::B(false); None } => 1,
26         //~^ ERROR cannot assign `x` in match guard
27         Enum::A(_) if let Some(()) = { let y = &mut x; *y = Enum::B(false); None } => 1,
28         //~^ ERROR cannot mutably borrow `x` in match guard
29         Enum::A(p) => *p,
30         Enum::B(_) => 2,
31     }
32 }
33
34 fn main() {}