1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // This is testing an attempt to corrupt the discriminant of the match
12 // arm in a guard, followed by an attempt to continue matching on that
13 // corrupted discriminant in the remaining match arms.
15 // Basically this is testing that our new NLL feature of emitting a
16 // fake read on each match arm is catching cases like this.
18 // This case is interesting because it includes a guard that
19 // diverges, and therefore a single final fake-read at the very end
20 // after the final match arm would not suffice.
22 // It is also interesting because the access to the corrupted data
23 // occurs in the pattern-match itself, and not in the guard
31 let mut x = &mut Some(&2);
32 let force_fn_once = ForceFnOnce;
34 &mut None => panic!("unreachable"),
37 // ForceFnOnce needed to exploit #27282
38 (|| { *x = None; drop(force_fn_once); })();
39 //~^ ERROR closure requires unique access to `x` but it is already borrowed [E0500]
43 // this segfaults if we corrupted the discriminant, because
44 // the compiler gets to *assume* that it cannot be the `None`
45 // case, even though that was the effect of the guard.
50 _ => panic!("unreachable"),