]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-migrate-to-nll.rs
e7f2bfbfedba79bd74840fe89c9c01ea140e4a09
[rust.git] / src / test / ui / borrowck / borrowck-migrate-to-nll.rs
1 // Copyright 2017 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.
4 //
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.
10
11 // This is a test of the borrowck migrate mode. It leverages #27282, a
12 // bug that is fixed by NLL: this code is (unsoundly) accepted by
13 // AST-borrowck, but is correctly rejected by the NLL borrowck.
14 //
15 // Therefore, for backwards-compatiblity, under borrowck=migrate the
16 // NLL checks will be emitted as *warnings*.
17
18 // NLL mode makes this compile-fail; we cannot currently encode a
19 // test that is run-pass or compile-fail based on compare-mode. So
20 // just ignore it instead:
21
22 // ignore-compare-mode-nll
23
24 // revisions: zflag edition
25 //[zflag]compile-flags: -Z borrowck=migrate
26 //[edition]compile-flags: --edition 2018
27 //[zflag] run-pass
28 //[edition] run-pass
29
30 fn main() {
31     match Some(&4) {
32         None => {},
33         ref mut foo
34             if {
35                 (|| { let bar = foo; bar.take() })();
36                 false
37             } => {},
38         Some(ref _s) => println!("Note this arm is bogus; the `Some` became `None` in the guard."),
39         _ => println!("Here is some supposedly unreachable code."),
40     }
41 }