Removed ignore-test-compare-mode-nll
from borrowck-closures-unique.rs
by strengthening the tests there. In almost all cases the strengthening amount to just encoding a use that models the original lexical lifetime. A more invasive revision was made in one case where it seems the actual issue is MIR-borrowck's greater "knowledge" of unreachable code in the control flow...
This commit is contained in:
parent
a5733050de
commit
dd9f84f2d3
54
src/test/ui/borrowck/borrowck-closures-unique.nll.stderr
Normal file
54
src/test/ui/borrowck/borrowck-closures-unique.nll.stderr
Normal file
@ -0,0 +1,54 @@
|
||||
error[E0500]: closure requires unique access to `x` but it is already borrowed
|
||||
--> $DIR/borrowck-closures-unique.rs:36:14
|
||||
|
|
||||
LL | let c1 = || get(x);
|
||||
| -- - first borrow occurs due to use of `x` in closure
|
||||
| |
|
||||
| borrow occurs here
|
||||
LL | let c2 = || set(x); //~ ERROR closure requires unique access to `x`
|
||||
| ^^ - second borrow occurs due to use of `x` in closure
|
||||
| |
|
||||
| closure construction occurs here
|
||||
LL | c1;
|
||||
| -- borrow later used here
|
||||
|
||||
error[E0500]: closure requires unique access to `x` but it is already borrowed
|
||||
--> $DIR/borrowck-closures-unique.rs:42:14
|
||||
|
|
||||
LL | let c1 = || get(x);
|
||||
| -- - first borrow occurs due to use of `x` in closure
|
||||
| |
|
||||
| borrow occurs here
|
||||
LL | let c2 = || { get(x); set(x); }; //~ ERROR closure requires unique access to `x`
|
||||
| ^^ - second borrow occurs due to use of `x` in closure
|
||||
| |
|
||||
| closure construction occurs here
|
||||
LL | c1;
|
||||
| -- borrow later used here
|
||||
|
||||
error[E0524]: two closures require unique access to `x` at the same time
|
||||
--> $DIR/borrowck-closures-unique.rs:48:14
|
||||
|
|
||||
LL | let c1 = || set(x);
|
||||
| -- - first borrow occurs due to use of `x` in closure
|
||||
| |
|
||||
| first closure is constructed here
|
||||
LL | let c2 = || set(x); //~ ERROR two closures require unique access to `x` at the same time
|
||||
| ^^ - second borrow occurs due to use of `x` in closure
|
||||
| |
|
||||
| second closure is constructed here
|
||||
LL | c1;
|
||||
| -- borrow later used here
|
||||
|
||||
error[E0594]: cannot assign to `x`, as it is not declared as mutable
|
||||
--> $DIR/borrowck-closures-unique.rs:57:38
|
||||
|
|
||||
LL | fn e(x: &'static mut isize) {
|
||||
| - help: consider changing this to be mutable: `mut x`
|
||||
LL | let c1 = |y: &'static mut isize| x = y; //~ ERROR closure cannot assign to immutable argument
|
||||
| ^^^^^ cannot assign
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors occurred: E0500, E0524, E0594.
|
||||
For more information about an error, try `rustc --explain E0500`.
|
@ -8,14 +8,14 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-compare-mode-nll
|
||||
|
||||
// Tests that a closure which requires mutable access to the referent
|
||||
// of an `&mut` requires a "unique" borrow -- that is, the variable to
|
||||
// be borrowed (here, `x`) will not be borrowed *mutably*, but
|
||||
// may be *immutable*, but we cannot allow
|
||||
// multiple borrows.
|
||||
|
||||
|
||||
|
||||
fn get(x: &isize) -> isize {
|
||||
*x
|
||||
}
|
||||
@ -27,25 +27,40 @@ fn set(x: &mut isize) -> isize {
|
||||
fn a(x: &mut isize) {
|
||||
let c1 = || get(x);
|
||||
let c2 = || get(x);
|
||||
c1();
|
||||
c2();
|
||||
}
|
||||
|
||||
fn b(x: &mut isize) {
|
||||
let c1 = || get(x);
|
||||
let c2 = || set(x); //~ ERROR closure requires unique access to `x`
|
||||
c1;
|
||||
}
|
||||
|
||||
fn c(x: &mut isize) {
|
||||
let c1 = || get(x);
|
||||
let c2 = || { get(x); set(x); }; //~ ERROR closure requires unique access to `x`
|
||||
c1;
|
||||
}
|
||||
|
||||
fn d(x: &mut isize) {
|
||||
let c1 = || set(x);
|
||||
let c2 = || set(x); //~ ERROR two closures require unique access to `x` at the same time
|
||||
c1;
|
||||
}
|
||||
|
||||
fn e(x: &mut isize) {
|
||||
// This test was originally encoded in the form shown as `fn f` below.
|
||||
// However, since MIR-borrowck and thus NLL takes more control-flow information
|
||||
// into account, it was necessary to change the test in order to witness the
|
||||
// same (expected) error under both AST-borrowck and NLL.
|
||||
fn e(x: &'static mut isize) {
|
||||
let c1 = |y: &'static mut isize| x = y; //~ ERROR closure cannot assign to immutable argument
|
||||
c1;
|
||||
}
|
||||
|
||||
fn f(x: &'static mut isize) {
|
||||
let c1 = || x = panic!(); //~ ERROR closure cannot assign to immutable argument
|
||||
c1;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0500]: closure requires unique access to `x` but it is already borrowed
|
||||
--> $DIR/borrowck-closures-unique.rs:34:14
|
||||
--> $DIR/borrowck-closures-unique.rs:36:14
|
||||
|
|
||||
LL | let c1 = || get(x);
|
||||
| -- - previous borrow occurs due to use of `x` in closure
|
||||
@ -9,11 +9,12 @@ LL | let c2 = || set(x); //~ ERROR closure requires unique access to `x`
|
||||
| ^^ - borrow occurs due to use of `x` in closure
|
||||
| |
|
||||
| closure construction occurs here
|
||||
LL | c1;
|
||||
LL | }
|
||||
| - borrow ends here
|
||||
|
||||
error[E0500]: closure requires unique access to `x` but it is already borrowed
|
||||
--> $DIR/borrowck-closures-unique.rs:39:14
|
||||
--> $DIR/borrowck-closures-unique.rs:42:14
|
||||
|
|
||||
LL | let c1 = || get(x);
|
||||
| -- - previous borrow occurs due to use of `x` in closure
|
||||
@ -23,11 +24,12 @@ LL | let c2 = || { get(x); set(x); }; //~ ERROR closure requires unique acce
|
||||
| ^^ - borrow occurs due to use of `x` in closure
|
||||
| |
|
||||
| closure construction occurs here
|
||||
LL | c1;
|
||||
LL | }
|
||||
| - borrow ends here
|
||||
|
||||
error[E0524]: two closures require unique access to `x` at the same time
|
||||
--> $DIR/borrowck-closures-unique.rs:44:14
|
||||
--> $DIR/borrowck-closures-unique.rs:48:14
|
||||
|
|
||||
LL | let c1 = || set(x);
|
||||
| -- - previous borrow occurs due to use of `x` in closure
|
||||
@ -37,11 +39,22 @@ LL | let c2 = || set(x); //~ ERROR two closures require unique access to `x`
|
||||
| ^^ - borrow occurs due to use of `x` in closure
|
||||
| |
|
||||
| second closure is constructed here
|
||||
LL | c1;
|
||||
LL | }
|
||||
| - borrow from first closure ends here
|
||||
|
||||
error[E0595]: closure cannot assign to immutable argument `x`
|
||||
--> $DIR/borrowck-closures-unique.rs:48:14
|
||||
--> $DIR/borrowck-closures-unique.rs:57:14
|
||||
|
|
||||
LL | let c1 = |y: &'static mut isize| x = y; //~ ERROR closure cannot assign to immutable argument
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot borrow mutably
|
||||
help: consider removing the `&mut`, as it is an immutable binding to a mutable reference
|
||||
|
|
||||
LL | x //~ ERROR closure cannot assign to immutable argument
|
||||
| ^
|
||||
|
||||
error[E0595]: closure cannot assign to immutable argument `x`
|
||||
--> $DIR/borrowck-closures-unique.rs:62:14
|
||||
|
|
||||
LL | let c1 = || x = panic!(); //~ ERROR closure cannot assign to immutable argument
|
||||
| ^^ cannot borrow mutably
|
||||
@ -50,7 +63,7 @@ help: consider removing the `&mut`, as it is an immutable binding to a mutable r
|
||||
LL | x //~ ERROR closure cannot assign to immutable argument
|
||||
| ^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Some errors occurred: E0500, E0524, E0595.
|
||||
For more information about an error, try `rustc --explain E0500`.
|
||||
|
Loading…
Reference in New Issue
Block a user