]>
Commit | Line | Data |
---|---|---|
0bf4aa26 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 a borrow of **x is untracked, because **x is | |
9 | // immutable. However, for matches we care that **x refers to the same value | |
10 | // until we have chosen a match arm. | |
e74abb32 | 11 | |
0bf4aa26 XL |
12 | struct ForceFnOnce; |
13 | fn main() { | |
14 | let mut x = &mut &Some(&2); | |
15 | let force_fn_once = ForceFnOnce; | |
16 | match **x { | |
17 | None => panic!("unreachable"), | |
18 | Some(&_) if { | |
19 | // ForceFnOnce needed to exploit #27282 | |
20 | (|| { *x = &None; drop(force_fn_once); })(); | |
21 | //~^ ERROR cannot mutably borrow `x` in match guard [E0510] | |
22 | false | |
23 | } => {} | |
24 | Some(&a) if { // this binds to garbage if we've corrupted discriminant | |
25 | println!("{}", a); | |
26 | panic!() | |
27 | } => {} | |
28 | _ => panic!("unreachable"), | |
29 | } | |
30 | } |