Skip to content

Commit ffdb881

Browse files
committed
auto merge of #14717 : zwarich/rust/borrowck-tests, r=cmr
After sitting down to build on the work merged in #14318, I realized that some of the test names were not clear, others probably weren't testing the right thing, and they were also not as exhaustive as they could have been.
2 parents 8e9e484 + 4666792 commit ffdb881

File tree

2 files changed

+133
-84
lines changed

2 files changed

+133
-84
lines changed

src/test/compile-fail/borrowck-field-sensitivity.rs

+38-20
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010

1111
struct A { a: int, b: Box<int> }
1212

13-
fn borrow<T>(_: &T) { }
14-
15-
fn use_after_move() {
13+
fn deref_after_move() {
1614
let x = A { a: 1, b: box 2 };
1715
drop(x.b);
1816
drop(*x.b); //~ ERROR use of partially moved value: `*x.b`
1917
}
2018

21-
fn use_after_fu_move() {
19+
fn deref_after_fu_move() {
2220
let x = A { a: 1, b: box 2 };
2321
let y = A { a: 3, .. x };
2422
drop(*x.b); //~ ERROR use of partially moved value: `*x.b`
@@ -27,35 +25,37 @@ fn use_after_fu_move() {
2725
fn borrow_after_move() {
2826
let x = A { a: 1, b: box 2 };
2927
drop(x.b);
30-
borrow(&x.b); //~ ERROR use of moved value: `x.b`
28+
let p = &x.b; //~ ERROR use of moved value: `x.b`
29+
drop(**p);
3130
}
3231

3332
fn borrow_after_fu_move() {
3433
let x = A { a: 1, b: box 2 };
3534
let _y = A { a: 3, .. x };
36-
borrow(&x.b); //~ ERROR use of moved value: `x.b`
35+
let p = &x.b; //~ ERROR use of moved value: `x.b`
36+
drop(**p);
3737
}
3838

3939
fn move_after_borrow() {
4040
let x = A { a: 1, b: box 2 };
41-
let y = &x.b;
41+
let p = &x.b;
4242
drop(x.b); //~ ERROR cannot move out of `x.b` because it is borrowed
43-
borrow(&*y);
43+
drop(**p);
4444
}
4545

4646
fn fu_move_after_borrow() {
4747
let x = A { a: 1, b: box 2 };
48-
let y = &x.b;
49-
let _z = A { a: 3, .. x }; //~ ERROR cannot move out of `x.b` because it is borrowed
50-
borrow(&*y);
48+
let p = &x.b;
49+
let _y = A { a: 3, .. x }; //~ ERROR cannot move out of `x.b` because it is borrowed
50+
drop(**p);
5151
}
5252

5353
fn mut_borrow_after_mut_borrow() {
5454
let mut x = A { a: 1, b: box 2 };
55-
let y = &mut x.a;
56-
let z = &mut x.a; //~ ERROR cannot borrow `x.a` as mutable more than once at a time
57-
drop(*y);
58-
drop(*z);
55+
let p = &mut x.a;
56+
let q = &mut x.a; //~ ERROR cannot borrow `x.a` as mutable more than once at a time
57+
drop(*p);
58+
drop(*q);
5959
}
6060

6161
fn move_after_move() {
@@ -84,7 +84,21 @@ fn fu_move_after_fu_move() {
8484

8585
// The following functions aren't yet accepted, but they should be.
8686

87-
fn use_after_field_assign_after_uninit() {
87+
fn move_after_borrow_correct() {
88+
let x = A { a: 1, b: box 2 };
89+
let p = &x.a;
90+
drop(x.b); //~ ERROR cannot move out of `x.b` because it is borrowed
91+
drop(*p);
92+
}
93+
94+
fn fu_move_after_borrow_correct() {
95+
let x = A { a: 1, b: box 2 };
96+
let p = &x.a;
97+
let _y = A { a: 3, .. x }; //~ ERROR cannot move out of `x.b` because it is borrowed
98+
drop(*p);
99+
}
100+
101+
fn copy_after_field_assign_after_uninit() {
88102
let mut x: A;
89103
x.a = 1;
90104
drop(x.a); //~ ERROR use of possibly uninitialized variable: `x.a`
@@ -93,7 +107,8 @@ fn use_after_field_assign_after_uninit() {
93107
fn borrow_after_field_assign_after_uninit() {
94108
let mut x: A;
95109
x.a = 1;
96-
borrow(&x.a); //~ ERROR use of possibly uninitialized variable: `x.a`
110+
let p = &x.a; //~ ERROR use of possibly uninitialized variable: `x.a`
111+
drop(*p);
97112
}
98113

99114
fn move_after_field_assign_after_uninit() {
@@ -103,8 +118,8 @@ fn move_after_field_assign_after_uninit() {
103118
}
104119

105120
fn main() {
106-
use_after_move();
107-
use_after_fu_move();
121+
deref_after_move();
122+
deref_after_fu_move();
108123

109124
borrow_after_move();
110125
borrow_after_fu_move();
@@ -117,7 +132,10 @@ fn main() {
117132
fu_move_after_move();
118133
fu_move_after_fu_move();
119134

120-
use_after_field_assign_after_uninit();
135+
move_after_borrow_correct();
136+
fu_move_after_borrow_correct();
137+
138+
copy_after_field_assign_after_uninit();
121139
borrow_after_field_assign_after_uninit();
122140
move_after_field_assign_after_uninit();
123141
}

0 commit comments

Comments
 (0)