Skip to content

Commit 653f57a

Browse files
author
Cameron Zwarich
committed
Fix bad borrowck tests and move them from run-pass to compile-fail
The move_after_borrow / fu_move_after_borrow tests in run-pass/borrowck-field-sensitivity.rs are not testing the right thing, since the scope of the borrow is limited to the call to borrow(). When fixed, these tests fail and thus should be moved to the corresponding compile-fail test file.
1 parent 61c81bf commit 653f57a

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ fn fu_move_after_fu_move() {
8484

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

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+
87101
fn copy_after_field_assign_after_uninit() {
88102
let mut x: A;
89103
x.a = 1;
@@ -117,6 +131,9 @@ fn main() {
117131
fu_move_after_move();
118132
fu_move_after_fu_move();
119133

134+
move_after_borrow_correct();
135+
fu_move_after_borrow_correct();
136+
120137
copy_after_field_assign_after_uninit();
121138
borrow_after_field_assign_after_uninit();
122139
move_after_field_assign_after_uninit();

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,6 @@ fn borrow_after_fu_move() {
7373
borrow(&x.a);
7474
}
7575

76-
fn move_after_borrow() {
77-
let x = A { a: 1, b: box 2 };
78-
borrow(&x.a);
79-
drop(x.b);
80-
}
81-
82-
fn fu_move_after_borrow() {
83-
let x = A { a: 1, b: box 2 };
84-
borrow(&x.a);
85-
let _y = A { a: 3, .. x };
86-
}
87-
8876
fn mut_borrow_after_mut_borrow() {
8977
let mut x = A { a: 1, b: box 2 };
9078
let y = &mut x.a;
@@ -232,8 +220,6 @@ fn main() {
232220

233221
borrow_after_move();
234222
borrow_after_fu_move();
235-
move_after_borrow();
236-
fu_move_after_borrow();
237223
mut_borrow_after_mut_borrow();
238224

239225
move_after_move();

0 commit comments

Comments
 (0)