Use revisions for NLL in borrowck
This commit is contained in:
parent
1e435e332e
commit
8220be5240
@ -1,5 +1,5 @@
|
||||
error[E0623]: lifetime mismatch
|
||||
--> $DIR/borrowck-reborrow-from-shorter-lived-andmut.rs:9:5
|
||||
--> $DIR/borrowck-reborrow-from-shorter-lived-andmut.rs:13:5
|
||||
|
|
||||
LL | fn copy_borrowed_ptr<'a,'b>(p: &'a mut S<'b>) -> S<'b> {
|
||||
| ------------- -----
|
@ -1,5 +1,5 @@
|
||||
error: lifetime may not live long enough
|
||||
--> $DIR/borrowck-reborrow-from-shorter-lived-andmut.rs:9:5
|
||||
--> $DIR/borrowck-reborrow-from-shorter-lived-andmut.rs:13:5
|
||||
|
|
||||
LL | fn copy_borrowed_ptr<'a,'b>(p: &'a mut S<'b>) -> S<'b> {
|
||||
| -- -- lifetime `'b` defined here
|
||||
|
@ -1,3 +1,7 @@
|
||||
// ignore-compare-mode-nll
|
||||
// revisions: base nll
|
||||
// [nll]compile-flags: -Zborrowck=mir
|
||||
|
||||
// Test that assignments to an `&mut` pointer which is found in a
|
||||
// borrowed (but otherwise non-aliasable) location is illegal.
|
||||
|
||||
@ -7,7 +11,8 @@ struct S<'a> {
|
||||
|
||||
fn copy_borrowed_ptr<'a,'b>(p: &'a mut S<'b>) -> S<'b> {
|
||||
S { pointer: &mut *p.pointer }
|
||||
//~^ ERROR lifetime mismatch
|
||||
//[base]~^ ERROR lifetime mismatch
|
||||
//[nll]~^^ ERROR lifetime may not live long enough
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
93
src/test/ui/borrowck/two-phase-nonrecv-autoref.base.stderr
Normal file
93
src/test/ui/borrowck/two-phase-nonrecv-autoref.base.stderr
Normal file
@ -0,0 +1,93 @@
|
||||
error[E0499]: cannot borrow `*f` as mutable more than once at a time
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:51:11
|
||||
|
|
||||
LL | f(f(10));
|
||||
| - ^ second mutable borrow occurs here
|
||||
| |
|
||||
| first mutable borrow occurs here
|
||||
| first borrow later used by call
|
||||
|
||||
error[E0382]: use of moved value: `f`
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:58:11
|
||||
|
|
||||
LL | fn twice_ten_so<F: FnOnce(i32) -> i32>(f: Box<F>) {
|
||||
| - move occurs because `f` has type `Box<F>`, which does not implement the `Copy` trait
|
||||
LL | f(f(10));
|
||||
| - ^ value used here after move
|
||||
| |
|
||||
| value moved here
|
||||
|
||||
error[E0499]: cannot borrow `*f` as mutable more than once at a time
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:63:11
|
||||
|
|
||||
LL | f(f(10));
|
||||
| - ^ second mutable borrow occurs here
|
||||
| |
|
||||
| first mutable borrow occurs here
|
||||
| first borrow later used by call
|
||||
|
||||
error[E0382]: use of moved value: `f`
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:70:11
|
||||
|
|
||||
LL | fn twice_ten_oo(f: Box<dyn FnOnce(i32) -> i32>) {
|
||||
| - move occurs because `f` has type `Box<dyn FnOnce(i32) -> i32>`, which does not implement the `Copy` trait
|
||||
LL | f(f(10));
|
||||
| - ^ value used here after move
|
||||
| |
|
||||
| value moved here
|
||||
|
||||
error[E0502]: cannot borrow `a` as immutable because it is also borrowed as mutable
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:108:27
|
||||
|
|
||||
LL | double_access(&mut a, &a);
|
||||
| ------------- ------ ^^ immutable borrow occurs here
|
||||
| | |
|
||||
| | mutable borrow occurs here
|
||||
| mutable borrow later used by call
|
||||
|
||||
error[E0502]: cannot borrow `i` as immutable because it is also borrowed as mutable
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:133:7
|
||||
|
|
||||
LL | i[i[3]] = 4;
|
||||
| --^----
|
||||
| | |
|
||||
| | immutable borrow occurs here
|
||||
| mutable borrow occurs here
|
||||
| mutable borrow later used here
|
||||
|
|
||||
help: try adding a local storing this...
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:133:7
|
||||
|
|
||||
LL | i[i[3]] = 4;
|
||||
| ^^^^
|
||||
help: ...and then using that local here
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:133:5
|
||||
|
|
||||
LL | i[i[3]] = 4;
|
||||
| ^^^^^^^
|
||||
|
||||
error[E0502]: cannot borrow `i` as immutable because it is also borrowed as mutable
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:139:7
|
||||
|
|
||||
LL | i[i[3]] = i[4];
|
||||
| --^----
|
||||
| | |
|
||||
| | immutable borrow occurs here
|
||||
| mutable borrow occurs here
|
||||
| mutable borrow later used here
|
||||
|
|
||||
help: try adding a local storing this...
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:139:7
|
||||
|
|
||||
LL | i[i[3]] = i[4];
|
||||
| ^^^^
|
||||
help: ...and then using that local here
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:139:5
|
||||
|
|
||||
LL | i[i[3]] = i[4];
|
||||
| ^^^^^^^
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0382, E0499, E0502.
|
||||
For more information about an error, try `rustc --explain E0382`.
|
@ -8,7 +8,7 @@ LL | f(f(10));
|
||||
| first borrow later used by call
|
||||
|
||||
error[E0382]: use of moved value: `f`
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:59:11
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:58:11
|
||||
|
|
||||
LL | fn twice_ten_so<F: FnOnce(i32) -> i32>(f: Box<F>) {
|
||||
| - move occurs because `f` has type `Box<F>`, which does not implement the `Copy` trait
|
||||
@ -18,7 +18,7 @@ LL | f(f(10));
|
||||
| value moved here
|
||||
|
||||
error[E0499]: cannot borrow `*f` as mutable more than once at a time
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:65:11
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:63:11
|
||||
|
|
||||
LL | f(f(10));
|
||||
| - ^ second mutable borrow occurs here
|
||||
@ -27,7 +27,7 @@ LL | f(f(10));
|
||||
| first borrow later used by call
|
||||
|
||||
error[E0382]: use of moved value: `f`
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:73:11
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:70:11
|
||||
|
|
||||
LL | fn twice_ten_oo(f: Box<dyn FnOnce(i32) -> i32>) {
|
||||
| - move occurs because `f` has type `Box<dyn FnOnce(i32) -> i32>`, which does not implement the `Copy` trait
|
||||
@ -37,7 +37,7 @@ LL | f(f(10));
|
||||
| value moved here
|
||||
|
||||
error[E0502]: cannot borrow `a` as immutable because it is also borrowed as mutable
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:112:27
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:108:27
|
||||
|
|
||||
LL | double_access(&mut a, &a);
|
||||
| ------------- ------ ^^ immutable borrow occurs here
|
||||
@ -46,7 +46,7 @@ LL | double_access(&mut a, &a);
|
||||
| mutable borrow later used by call
|
||||
|
||||
error[E0502]: cannot borrow `i` as immutable because it is also borrowed as mutable
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:138:7
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:133:7
|
||||
|
|
||||
LL | i[i[3]] = 4;
|
||||
| --^----
|
||||
@ -56,18 +56,18 @@ LL | i[i[3]] = 4;
|
||||
| mutable borrow later used here
|
||||
|
|
||||
help: try adding a local storing this...
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:138:7
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:133:7
|
||||
|
|
||||
LL | i[i[3]] = 4;
|
||||
| ^^^^
|
||||
help: ...and then using that local here
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:138:5
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:133:5
|
||||
|
|
||||
LL | i[i[3]] = 4;
|
||||
| ^^^^^^^
|
||||
|
||||
error[E0502]: cannot borrow `i` as immutable because it is also borrowed as mutable
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:143:7
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:139:7
|
||||
|
|
||||
LL | i[i[3]] = i[4];
|
||||
| --^----
|
||||
@ -77,12 +77,12 @@ LL | i[i[3]] = i[4];
|
||||
| mutable borrow later used here
|
||||
|
|
||||
help: try adding a local storing this...
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:143:7
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:139:7
|
||||
|
|
||||
LL | i[i[3]] = i[4];
|
||||
| ^^^^
|
||||
help: ...and then using that local here
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:143:5
|
||||
--> $DIR/two-phase-nonrecv-autoref.rs:139:5
|
||||
|
|
||||
LL | i[i[3]] = i[4];
|
||||
| ^^^^^^^
|
||||
|
@ -1,4 +1,4 @@
|
||||
// revisions: nll
|
||||
// revisions: base nll
|
||||
//[nll]compile-flags: -Z borrowck=mir
|
||||
|
||||
//[g2p]compile-flags: -Z borrowck=mir -Z two-phase-beyond-autoref
|
||||
@ -49,30 +49,26 @@ fn overloaded_call_traits() {
|
||||
|
||||
fn twice_ten_sm<F: FnMut(i32) -> i32>(f: &mut F) {
|
||||
f(f(10));
|
||||
//[nll]~^ ERROR cannot borrow `*f` as mutable more than once at a time
|
||||
//[g2p]~^^ ERROR cannot borrow `*f` as mutable more than once at a time
|
||||
//~^ ERROR cannot borrow `*f` as mutable more than once at a time
|
||||
}
|
||||
fn twice_ten_si<F: Fn(i32) -> i32>(f: &mut F) {
|
||||
f(f(10));
|
||||
}
|
||||
fn twice_ten_so<F: FnOnce(i32) -> i32>(f: Box<F>) {
|
||||
f(f(10));
|
||||
//[nll]~^ ERROR use of moved value: `f`
|
||||
//[g2p]~^^ ERROR use of moved value: `f`
|
||||
//~^ ERROR use of moved value: `f`
|
||||
}
|
||||
|
||||
fn twice_ten_om(f: &mut dyn FnMut(i32) -> i32) {
|
||||
f(f(10));
|
||||
//[nll]~^ ERROR cannot borrow `*f` as mutable more than once at a time
|
||||
//[g2p]~^^ ERROR cannot borrow `*f` as mutable more than once at a time
|
||||
//~^ ERROR cannot borrow `*f` as mutable more than once at a time
|
||||
}
|
||||
fn twice_ten_oi(f: &mut dyn Fn(i32) -> i32) {
|
||||
f(f(10));
|
||||
}
|
||||
fn twice_ten_oo(f: Box<dyn FnOnce(i32) -> i32>) {
|
||||
f(f(10));
|
||||
//[nll]~^ ERROR use of moved value: `f`
|
||||
//[g2p]~^^ ERROR use of moved value: `f`
|
||||
//~^ ERROR use of moved value: `f`
|
||||
}
|
||||
|
||||
twice_ten_sm(&mut |x| x + 1);
|
||||
@ -110,8 +106,7 @@ fn coerce_unsized() {
|
||||
|
||||
// This is not okay.
|
||||
double_access(&mut a, &a);
|
||||
//[nll]~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable [E0502]
|
||||
//[g2p]~^^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable [E0502]
|
||||
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable [E0502]
|
||||
|
||||
// But this is okay.
|
||||
a.m(a.i(10));
|
||||
@ -136,12 +131,14 @@ impl IndexMut<i32> for I {
|
||||
fn coerce_index_op() {
|
||||
let mut i = I(10);
|
||||
i[i[3]] = 4;
|
||||
//[nll]~^ ERROR cannot borrow `i` as immutable because it is also borrowed as mutable [E0502]
|
||||
//~^ ERROR cannot borrow `i` as immutable because it is also borrowed as mutable [E0502]
|
||||
// Shoud be accepted with g2p
|
||||
|
||||
i[3] = i[4];
|
||||
|
||||
i[i[3]] = i[4];
|
||||
//[nll]~^ ERROR cannot borrow `i` as immutable because it is also borrowed as mutable [E0502]
|
||||
//~^ ERROR cannot borrow `i` as immutable because it is also borrowed as mutable [E0502]
|
||||
// Shoud be accepted with g2p
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user