]>
Commit | Line | Data |
---|---|---|
94b46f34 XL |
1 | // This is testing an attempt to corrupt the discriminant of the match |
2 | // arm in a guard, followed by an attempt to continue matching on that | |
3 | // corrupted discriminant in the remaining match arms. | |
4 | // | |
5 | // Basically this is testing that our new NLL feature of emitting a | |
6 | // fake read on each match arm is catching cases like this. | |
7 | // | |
8 | // This case is interesting because it includes a guard that | |
9 | // diverges, and therefore a single final fake-read at the very end | |
10 | // after the final match arm would not suffice. | |
11 | ||
94b46f34 XL |
12 | struct ForceFnOnce; |
13 | ||
14 | fn main() { | |
15 | let mut x = &mut Some(&2); | |
16 | let force_fn_once = ForceFnOnce; | |
17 | match x { | |
18 | &mut None => panic!("unreachable"), | |
19 | &mut Some(&_) if { | |
20 | // ForceFnOnce needed to exploit #27282 | |
21 | (|| { *x = None; drop(force_fn_once); })(); | |
0bf4aa26 | 22 | //~^ ERROR cannot mutably borrow `x` in match guard [E0510] |
94b46f34 XL |
23 | false |
24 | } => {} | |
25 | &mut Some(&a) if { // this binds to garbage if we've corrupted discriminant | |
26 | println!("{}", a); | |
27 | panic!() | |
28 | } => {} | |
29 | _ => panic!("unreachable"), | |
30 | } | |
31 | } |