File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 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+ // compile-flags: -Z borrowck=migrate
19+ // run-pass
20+
21+ fn main ( ) {
22+ match Some ( & 4 ) {
23+ None => { } ,
24+ ref mut foo
25+ if {
26+ ( || { let bar = foo; bar. take ( ) } ) ( ) ;
27+ false
28+ } => { } ,
29+ Some ( ref _s) => println ! ( "Note this arm is bogus; the `Some` became `None` in the guard." ) ,
30+ _ => println ! ( "Here is some supposedly unreachable code." ) ,
31+ }
32+ }
Original file line number Diff line number Diff line change 1+ warning[E0507]: cannot move out of borrowed content
2+ --> $DIR/borrowck-migrate-to-nll.rs:26:17
3+ |
4+ LL | (|| { let bar = foo; bar.take() })();
5+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content
6+ |
7+ = warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
8+ It represents potential unsoundness in your code.
9+ This warning will become a hard error in the future.
10+
11+ warning[E0507]: cannot move out of `foo`, as it is immutable for the pattern guard
12+ --> $DIR/borrowck-migrate-to-nll.rs:26:17
13+ |
14+ LL | (|| { let bar = foo; bar.take() })();
15+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+ | |
17+ | cannot move out of `foo`, as it is immutable for the pattern guard
18+ | cannot move
19+ |
20+ = note: variables bound in patterns are immutable until the end of the pattern guard
21+ = warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
22+ It represents potential unsoundness in your code.
23+ This warning will become a hard error in the future.
24+
You can’t perform that action at this time.
0 commit comments