Skip to content

Commit 4666792

Browse files
author
Cameron Zwarich
committed
Clean up borrows in borrowck field-sensitivity tests
Instead of calling a borrow() function that takes a pointer type, just create a local pointer and dereference it. The dereference is there to outsmart any future liveness analysis in borrowck.
1 parent 653f57a commit 4666792

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

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

+15-14
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

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

13-
fn borrow<T>(_: &T) { }
14-
1513
fn deref_after_move() {
1614
let x = A { a: 1, b: box 2 };
1715
drop(x.b);
@@ -27,35 +25,37 @@ fn deref_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() {
@@ -107,7 +107,8 @@ fn copy_after_field_assign_after_uninit() {
107107
fn borrow_after_field_assign_after_uninit() {
108108
let mut x: A;
109109
x.a = 1;
110-
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);
111112
}
112113

113114
fn move_after_field_assign_after_uninit() {

src/test/run-pass/borrowck-field-sensitivity.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
struct A { a: int, b: Box<int> }
1212
struct B { a: Box<int>, b: Box<int> }
1313

14-
fn borrow<T>(_: &T) { }
15-
1614
fn move_after_copy() {
1715
let x = A { a: 1, b: box 2 };
1816
drop(x.a);
@@ -64,21 +62,23 @@ fn fu_copy_after_fu_move() {
6462
fn borrow_after_move() {
6563
let x = A { a: 1, b: box 2 };
6664
drop(x.b);
67-
borrow(&x.a);
65+
let p = &x.a;
66+
drop(*p);
6867
}
6968

7069
fn borrow_after_fu_move() {
7170
let x = A { a: 1, b: box 2 };
7271
let _y = A { a: 3, .. x };
73-
borrow(&x.a);
72+
let p = &x.a;
73+
drop(*p);
7474
}
7575

7676
fn mut_borrow_after_mut_borrow() {
7777
let mut x = A { a: 1, b: box 2 };
78-
let y = &mut x.a;
79-
let z = &mut x.b;
80-
drop(*y);
81-
drop(**z);
78+
let p = &mut x.a;
79+
let q = &mut x.b;
80+
drop(*p);
81+
drop(**q);
8282
}
8383

8484
fn move_after_move() {
@@ -138,28 +138,32 @@ fn borrow_after_assign_after_move() {
138138
let mut x = A { a: 1, b: box 2 };
139139
drop(x.b);
140140
x = A { a: 3, b: box 4 };
141-
borrow(&x.b);
141+
let p = &x.b;
142+
drop(**p);
142143
}
143144

144145
fn borrow_after_assign_after_fu_move() {
145146
let mut x = A { a: 1, b: box 2 };
146147
let _y = A { a: 3, .. x };
147148
x = A { a: 3, b: box 4 };
148-
borrow(&x.b);
149+
let p = &x.b;
150+
drop(**p);
149151
}
150152

151153
fn borrow_after_field_assign_after_move() {
152154
let mut x = A { a: 1, b: box 2 };
153155
drop(x.b);
154156
x.b = box 3;
155-
borrow(&x.b);
157+
let p = &x.b;
158+
drop(**p);
156159
}
157160

158161
fn borrow_after_field_assign_after_fu_move() {
159162
let mut x = A { a: 1, b: box 2 };
160163
let _y = A { a: 3, .. x };
161164
x.b = box 3;
162-
borrow(&x.b);
165+
let p = &x.b;
166+
drop(**p);
163167
}
164168

165169
fn move_after_assign_after_move() {
@@ -199,7 +203,8 @@ fn copy_after_assign_after_uninit() {
199203
fn borrow_after_assign_after_uninit() {
200204
let mut x: A;
201205
x = A { a: 1, b: box 2 };
202-
borrow(&x.a);
206+
let p = &x.a;
207+
drop(*p);
203208
}
204209

205210
fn move_after_assign_after_uninit() {

0 commit comments

Comments
 (0)