Skip to content

Commit 5f524ed

Browse files
committed
Switch to using revisions in borrowck-lend-flow-loop.rs
Most of the time we want to robustify tests, but in this case this test is deliberately encoding artifacts of AST-borrowck. So instead of adding artificial uses that would obscure the aspects of AST-borrowck that are being tests, we instead use revisions and then mark the cases that apply to NLL as well as AST-borrowck.
1 parent 6cfc603 commit 5f524ed

File tree

3 files changed

+41
-41
lines changed

3 files changed

+41
-41
lines changed

src/test/ui/borrowck/borrowck-lend-flow-loop.stderr renamed to src/test/ui/borrowck/borrowck-lend-flow-loop.ast.stderr

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0502]: cannot borrow `*v` as immutable because `v` is also borrowed as mu
44
LL | let mut x = &mut v;
55
| - mutable borrow occurs here
66
...
7-
LL | borrow(&*v); //~ ERROR cannot borrow
7+
LL | borrow(&*v); //[ast]~ ERROR cannot borrow
88
| ^^ immutable borrow occurs here
99
LL | }
1010
LL | }
@@ -16,7 +16,7 @@ error[E0502]: cannot borrow `*v` as immutable because `v` is also borrowed as mu
1616
LL | let mut x = &mut v;
1717
| - mutable borrow occurs here
1818
LL | for _ in 0..3 {
19-
LL | borrow(&*v); //~ ERROR cannot borrow
19+
LL | borrow(&*v); //[ast]~ ERROR cannot borrow
2020
| ^^ immutable borrow occurs here
2121
...
2222
LL | }
@@ -25,7 +25,7 @@ LL | }
2525
error[E0502]: cannot borrow `*v` as mutable because `v` is also borrowed as immutable
2626
--> $DIR/borrowck-lend-flow-loop.rs:57:25
2727
|
28-
LL | borrow_mut(&mut *v); //~ ERROR cannot borrow
28+
LL | borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow
2929
| ^^ mutable borrow occurs here
3030
LL | _x = &v;
3131
| - immutable borrow occurs here
@@ -36,7 +36,7 @@ LL | }
3636
error[E0502]: cannot borrow `*v` as mutable because `v` is also borrowed as immutable
3737
--> $DIR/borrowck-lend-flow-loop.rs:69:25
3838
|
39-
LL | borrow_mut(&mut *v); //~ ERROR cannot borrow
39+
LL | borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow
4040
| ^^ mutable borrow occurs here
4141
LL | _x = &v;
4242
| - immutable borrow occurs here
@@ -50,7 +50,7 @@ error[E0502]: cannot borrow `*v` as mutable because `v` is also borrowed as immu
5050
LL | _x = &v;
5151
| - immutable borrow occurs here
5252
...
53-
LL | borrow_mut(&mut *v); //~ ERROR cannot borrow
53+
LL | borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow
5454
| ^^ mutable borrow occurs here
5555
LL | }
5656
| - immutable borrow ends here
@@ -61,27 +61,27 @@ error[E0502]: cannot borrow `*v` as mutable because `v` is also borrowed as immu
6161
LL | _x = &v;
6262
| - immutable borrow occurs here
6363
...
64-
LL | borrow_mut(&mut *v); //~ ERROR cannot borrow
64+
LL | borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow
6565
| ^^ mutable borrow occurs here
6666
LL | }
6767
| - immutable borrow ends here
6868

6969
error[E0502]: cannot borrow `*v` as immutable because `v` is also borrowed as mutable
7070
--> $DIR/borrowck-lend-flow-loop.rs:109:17
7171
|
72-
LL | borrow(&*v); //~ ERROR cannot borrow
72+
LL | borrow(&*v); //[ast]~ ERROR cannot borrow
7373
| ^^ immutable borrow occurs here
74-
LL | if cond2 {
75-
LL | x = &mut v; //~ ERROR cannot borrow
74+
...
75+
LL | x = &mut v; //[ast]~ ERROR cannot borrow
7676
| - mutable borrow occurs here
7777
...
7878
LL | }
7979
| - mutable borrow ends here
8080

8181
error[E0499]: cannot borrow `v` as mutable more than once at a time
82-
--> $DIR/borrowck-lend-flow-loop.rs:111:22
82+
--> $DIR/borrowck-lend-flow-loop.rs:112:22
8383
|
84-
LL | x = &mut v; //~ ERROR cannot borrow
84+
LL | x = &mut v; //[ast]~ ERROR cannot borrow
8585
| ^ mutable borrow starts here in previous iteration of loop
8686
...
8787
LL | }

src/test/ui/borrowck/borrowck-lend-flow-loop.nll.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ error[E0502]: cannot borrow `*v` as immutable because it is also borrowed as mut
44
LL | let mut x = &mut v;
55
| ------ mutable borrow occurs here
66
LL | for _ in 0..3 {
7-
LL | borrow(&*v); //~ ERROR cannot borrow
7+
LL | borrow(&*v); //[ast]~ ERROR cannot borrow
88
| ^^^ immutable borrow occurs here
9-
LL | }
9+
...
1010
LL | *x = box 5;
1111
| -- mutable borrow used here, in later iteration of loop
1212

@@ -15,10 +15,10 @@ error[E0502]: cannot borrow `*v` as immutable because it is also borrowed as mut
1515
|
1616
LL | **x += 1;
1717
| -------- mutable borrow used here, in later iteration of loop
18-
LL | borrow(&*v); //~ ERROR cannot borrow
18+
LL | borrow(&*v); //[ast]~ ERROR cannot borrow
1919
| ^^^ immutable borrow occurs here
20-
LL | if cond2 {
21-
LL | x = &mut v; //~ ERROR cannot borrow
20+
...
21+
LL | x = &mut v; //[ast]~ ERROR cannot borrow
2222
| ------ mutable borrow occurs here
2323

2424
error: aborting due to 2 previous errors

src/test/ui/borrowck/borrowck-lend-flow-loop.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
// Copyright 2012 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-
// Note: the borrowck analysis is currently flow-insensitive.
12-
// Therefore, some of these errors are marked as spurious and could be
13-
// corrected by a simple change to the analysis. The others are
14-
// either genuine or would require more advanced changes. The latter
15-
// cases are noted.
1+
// revisions: ast nll
2+
3+
// Since we are testing nll migration explicitly as a separate
4+
// revision, don't worry about the --compare-mode=nll on this test.
5+
6+
// ignore-compare-mode-nll
7+
8+
//[ast]compile-flags: -Z borrowck=ast
9+
//[nll]compile-flags: -Z borrowck=migrate -Z two-phase-borrows
10+
11+
// Note: the borrowck analysis was originally a flow-insensitive pass
12+
// over the AST. Therefore, some of these (AST) errors are marked as
13+
// spurious and are corrected by the flow-sensitive (NLL) analysis.
14+
// The others are either genuine or would require more advanced
15+
// changes. The latter cases are noted.
1616

1717
#![feature(box_syntax)]
1818

@@ -32,7 +32,7 @@ fn loop_overarching_alias_mut() {
3232
let mut x = &mut v;
3333
**x += 1;
3434
loop {
35-
borrow(&*v); //~ ERROR cannot borrow
35+
borrow(&*v); //[ast]~ ERROR cannot borrow
3636
}
3737
}
3838

@@ -42,19 +42,19 @@ fn block_overarching_alias_mut() {
4242
let mut v: Box<_> = box 3;
4343
let mut x = &mut v;
4444
for _ in 0..3 {
45-
borrow(&*v); //~ ERROR cannot borrow
45+
borrow(&*v); //[ast]~ ERROR cannot borrow
46+
//[nll]~^ ERROR cannot borrow
4647
}
4748
*x = box 5;
4849
}
49-
5050
fn loop_aliased_mut() {
5151
// In this instance, the borrow is carried through the loop.
5252

5353
let mut v: Box<_> = box 3;
5454
let mut w: Box<_> = box 4;
5555
let mut _x = &w;
5656
loop {
57-
borrow_mut(&mut *v); //~ ERROR cannot borrow
57+
borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow
5858
_x = &v;
5959
}
6060
}
@@ -66,7 +66,7 @@ fn while_aliased_mut() {
6666
let mut w: Box<_> = box 4;
6767
let mut _x = &w;
6868
while cond() {
69-
borrow_mut(&mut *v); //~ ERROR cannot borrow
69+
borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow
7070
_x = &v;
7171
}
7272
}
@@ -83,7 +83,7 @@ fn loop_aliased_mut_break() {
8383
_x = &v;
8484
break;
8585
}
86-
borrow_mut(&mut *v); //~ ERROR cannot borrow
86+
borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow
8787
}
8888

8989
fn while_aliased_mut_break() {
@@ -97,7 +97,7 @@ fn while_aliased_mut_break() {
9797
_x = &v;
9898
break;
9999
}
100-
borrow_mut(&mut *v); //~ ERROR cannot borrow
100+
borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow
101101
}
102102

103103
fn while_aliased_mut_cond(cond: bool, cond2: bool) {
@@ -106,13 +106,13 @@ fn while_aliased_mut_cond(cond: bool, cond2: bool) {
106106
let mut x = &mut w;
107107
while cond {
108108
**x += 1;
109-
borrow(&*v); //~ ERROR cannot borrow
109+
borrow(&*v); //[ast]~ ERROR cannot borrow
110+
//[nll]~^ ERROR cannot borrow
110111
if cond2 {
111-
x = &mut v; //~ ERROR cannot borrow
112+
x = &mut v; //[ast]~ ERROR cannot borrow
112113
}
113114
}
114115
}
115-
116116
fn loop_break_pops_scopes<'r, F>(_v: &'r mut [usize], mut f: F) where
117117
F: FnMut(&'r mut usize) -> bool,
118118
{

0 commit comments

Comments
 (0)