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.
16
16
17
17
#![ feature( box_syntax) ]
18
18
@@ -32,7 +32,7 @@ fn loop_overarching_alias_mut() {
32
32
let mut x = & mut v;
33
33
* * x += 1 ;
34
34
loop {
35
- borrow ( & * v) ; //~ ERROR cannot borrow
35
+ borrow ( & * v) ; //[ast] ~ ERROR cannot borrow
36
36
}
37
37
}
38
38
@@ -42,19 +42,19 @@ fn block_overarching_alias_mut() {
42
42
let mut v: Box < _ > = box 3 ;
43
43
let mut x = & mut v;
44
44
for _ in 0 ..3 {
45
- borrow ( & * v) ; //~ ERROR cannot borrow
45
+ borrow ( & * v) ; //[ast]~ ERROR cannot borrow
46
+ //[nll]~^ ERROR cannot borrow
46
47
}
47
48
* x = box 5 ;
48
49
}
49
-
50
50
fn loop_aliased_mut ( ) {
51
51
// In this instance, the borrow is carried through the loop.
52
52
53
53
let mut v: Box < _ > = box 3 ;
54
54
let mut w: Box < _ > = box 4 ;
55
55
let mut _x = & w;
56
56
loop {
57
- borrow_mut ( & mut * v) ; //~ ERROR cannot borrow
57
+ borrow_mut ( & mut * v) ; //[ast] ~ ERROR cannot borrow
58
58
_x = & v;
59
59
}
60
60
}
@@ -66,7 +66,7 @@ fn while_aliased_mut() {
66
66
let mut w: Box < _ > = box 4 ;
67
67
let mut _x = & w;
68
68
while cond ( ) {
69
- borrow_mut ( & mut * v) ; //~ ERROR cannot borrow
69
+ borrow_mut ( & mut * v) ; //[ast] ~ ERROR cannot borrow
70
70
_x = & v;
71
71
}
72
72
}
@@ -83,7 +83,7 @@ fn loop_aliased_mut_break() {
83
83
_x = & v;
84
84
break ;
85
85
}
86
- borrow_mut ( & mut * v) ; //~ ERROR cannot borrow
86
+ borrow_mut ( & mut * v) ; //[ast] ~ ERROR cannot borrow
87
87
}
88
88
89
89
fn while_aliased_mut_break ( ) {
@@ -97,7 +97,7 @@ fn while_aliased_mut_break() {
97
97
_x = & v;
98
98
break ;
99
99
}
100
- borrow_mut ( & mut * v) ; //~ ERROR cannot borrow
100
+ borrow_mut ( & mut * v) ; //[ast] ~ ERROR cannot borrow
101
101
}
102
102
103
103
fn while_aliased_mut_cond ( cond : bool , cond2 : bool ) {
@@ -106,13 +106,13 @@ fn while_aliased_mut_cond(cond: bool, cond2: bool) {
106
106
let mut x = & mut w;
107
107
while cond {
108
108
* * x += 1 ;
109
- borrow ( & * v) ; //~ ERROR cannot borrow
109
+ borrow ( & * v) ; //[ast]~ ERROR cannot borrow
110
+ //[nll]~^ ERROR cannot borrow
110
111
if cond2 {
111
- x = & mut v; //~ ERROR cannot borrow
112
+ x = & mut v; //[ast] ~ ERROR cannot borrow
112
113
}
113
114
}
114
115
}
115
-
116
116
fn loop_break_pops_scopes < ' r , F > ( _v : & ' r mut [ usize ] , mut f : F ) where
117
117
F : FnMut ( & ' r mut usize ) -> bool ,
118
118
{
0 commit comments