File tree Expand file tree Collapse file tree 3 files changed +32
-30
lines changed Expand file tree Collapse file tree 3 files changed +32
-30
lines changed Original file line number Diff line number Diff line change 1- warning[E0507 ]: cannot move out of `foo` in pattern guard
2- --> $DIR/borrowck-migrate-to-nll.rs:26:18
1+ warning[E0502 ]: cannot borrow `*block.current` as immutable because it is also borrowed as mutable
2+ --> $DIR/borrowck-migrate-to-nll.rs:28:21
33 |
4- LL | (|| { let bar = foo; bar.take() })();
5- | ^^ ---
6- | | |
7- | | move occurs because `foo` has type `&mut std::option::Option<&i32>`, which does not implement the `Copy` trait
8- | | move occurs due to use in closure
9- | move out of `foo` occurs here
4+ LL | let x = &mut block;
5+ | ---------- mutable borrow occurs here
6+ LL | let p: &'a u8 = &*block.current;
7+ | ^^^^^^^^^^^^^^^ immutable borrow occurs here
8+ LL | // (use `x` and `p` so enabling NLL doesn't assign overly short lifetimes)
9+ LL | drop(x);
10+ | - mutable borrow later used here
1011 |
11- = note: variables bound in patterns cannot be moved from until after the end of the pattern guard
1212 = warning: this error has been downgraded to a warning for backwards compatibility with previous releases
1313 = warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future
1414 = note: for more information, try `rustc --explain E0729`
Original file line number Diff line number Diff line change 1- // This is a test of the borrowck migrate mode. It leverages #27282 , a
1+ // This is a test of the borrowck migrate mode. It leverages #38899 , a
22// bug that is fixed by NLL: this code is (unsoundly) accepted by
33// AST-borrowck, but is correctly rejected by the NLL borrowck.
44//
1818//[zflag] run-pass
1919//[edition] run-pass
2020
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- }
21+ pub struct Block < ' a > {
22+ current : & ' a u8 ,
23+ unrelated : & ' a u8 ,
3224}
25+
26+ fn bump < ' a > ( mut block : & mut Block < ' a > ) {
27+ let x = & mut block;
28+ let p: & ' a u8 = & * block. current ;
29+ // (use `x` and `p` so enabling NLL doesn't assign overly short lifetimes)
30+ drop ( x) ;
31+ drop ( p) ;
32+ }
33+
34+ fn main ( ) { }
Original file line number Diff line number Diff line change 1- warning[E0507 ]: cannot move out of `foo` in pattern guard
2- --> $DIR/borrowck-migrate-to-nll.rs:26:18
1+ warning[E0502 ]: cannot borrow `*block.current` as immutable because it is also borrowed as mutable
2+ --> $DIR/borrowck-migrate-to-nll.rs:28:21
33 |
4- LL | (|| { let bar = foo; bar.take() })();
5- | ^^ ---
6- | | |
7- | | move occurs because `foo` has type `&mut std::option::Option<&i32>`, which does not implement the `Copy` trait
8- | | move occurs due to use in closure
9- | move out of `foo` occurs here
4+ LL | let x = &mut block;
5+ | ---------- mutable borrow occurs here
6+ LL | let p: &'a u8 = &*block.current;
7+ | ^^^^^^^^^^^^^^^ immutable borrow occurs here
8+ LL | // (use `x` and `p` so enabling NLL doesn't assign overly short lifetimes)
9+ LL | drop(x);
10+ | - mutable borrow later used here
1011 |
11- = note: variables bound in patterns cannot be moved from until after the end of the pattern guard
1212 = warning: this error has been downgraded to a warning for backwards compatibility with previous releases
1313 = warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future
1414 = note: for more information, try `rustc --explain E0729`
You can’t perform that action at this time.
0 commit comments