Skip to content

Commit 4583272

Browse files
committed
Updates to tests reflecting array-move restrictions.
Note that the change to the error message in borrowck-use-in-index-lvalue.rs, where we report that `*w` is uninitialized rather than `w`, was unintended fallout from the implementation strategy used here. The change appears harmless to me, but I welcome advice on how to bring back the old message, which was slightly cleaner (i.e. less unintelligible). ---- drive-by: revise compile-fail/borrowck-vec-pattern-move-tail to make it really clear that there is a conflict that must be signaled. (A hypothetical future version of Rust might be able to accept the prior version of the code, since the previously updated index was not actually aliased.)
1 parent 128ac9d commit 4583272

File tree

4 files changed

+5
-80
lines changed

4 files changed

+5
-80
lines changed

src/test/compile-fail/borrowck-array-double-move.rs

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/test/compile-fail/borrowck-use-in-index-lvalue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
fn test() {
1212
let w: &mut [isize];
13-
w[5] = 0; //~ ERROR use of possibly uninitialized variable: `w`
13+
w[5] = 0; //~ ERROR use of possibly uninitialized variable: `*w`
1414

1515
let mut w: &mut [isize];
16-
w[5] = 0; //~ ERROR use of possibly uninitialized variable: `w`
16+
w[5] = 0; //~ ERROR use of possibly uninitialized variable: `*w`
1717
}
1818

1919
fn main() { test(); }

src/test/compile-fail/borrowck-vec-pattern-move-tail.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ fn main() {
1414
[1, 2, tail..] => tail,
1515
_ => unreachable!()
1616
};
17-
a[0] = 0; //~ ERROR cannot assign to `a[..]` because it is borrowed
17+
println!("t[0]: {}", t[0]);
18+
a[2] = 0; //~ ERROR cannot assign to `a[..]` because it is borrowed
19+
println!("t[0]: {}", t[0]);
1820
t[0];
1921
}

src/test/compile-fail/move-fragments-9.rs

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,6 @@ pub fn test_move_array_into_recv(a: [D; 3], recv: &mut [D; 3]) {
3333
*recv = a;
3434
}
3535

36-
#[rustc_move_fragments]
37-
pub fn test_extract_array_elem(a: [D; 3], i: usize) -> D {
38-
//~^ ERROR parent_of_fragments: `$(local a)`
39-
//~| ERROR assigned_leaf_path: `$(local i)`
40-
//~| ERROR moved_leaf_path: `$(local a).[]`
41-
//~| ERROR unmoved_fragment: `$(allbutone $(local a).[])`
42-
a[i]
43-
}
44-
4536
#[rustc_move_fragments]
4637
pub fn test_overwrite_array_elem(mut a: [D; 3], i: usize, d: D) {
4738
//~^ ERROR parent_of_fragments: `$(local mut a)`
@@ -53,48 +44,4 @@ pub fn test_overwrite_array_elem(mut a: [D; 3], i: usize, d: D) {
5344
a[i] = d;
5445
}
5546

56-
// FIXME (pnkfelix): Both test_move_array_then_overwrite_elem1 and
57-
// test_move_array_then_overwrite_elem2 illustrate a behavior that
58-
// we need to make illegal if we want to get rid of drop-flags.
59-
// See RFC PR 320 for more discussion.
60-
61-
#[rustc_move_fragments]
62-
pub fn test_move_array_then_overwrite_elem1(mut a: [D; 3], i: usize, recv: &mut [D; 3], d: D) {
63-
//~^ ERROR parent_of_fragments: `$(local mut a)`
64-
//~| ERROR parent_of_fragments: `$(local recv)`
65-
//~| ERROR assigned_leaf_path: `$(local recv).*`
66-
//~| ERROR assigned_leaf_path: `$(local i)`
67-
//~| ERROR assigned_leaf_path: `$(local d)`
68-
//~| ERROR moved_leaf_path: `$(local d)`
69-
//~| ERROR assigned_leaf_path: `$(local mut a).[]`
70-
//~| ERROR unmoved_fragment: `$(allbutone $(local mut a).[])`
71-
72-
// This test covers the case where the array contents have been all moved away, but
73-
// we still need to deal with new initializing writes into the array.
74-
*recv = a;
75-
a[i] = d;
76-
}
77-
78-
#[rustc_move_fragments]
79-
pub fn test_move_array_then_overwrite_elem2(mut a: [D; 3], i: usize, j: usize,
80-
recv: &mut [D; 3], d1: D, d2: D) {
81-
//~^^ ERROR parent_of_fragments: `$(local mut a)`
82-
//~| ERROR parent_of_fragments: `$(local recv)`
83-
//~| ERROR assigned_leaf_path: `$(local recv).*`
84-
//~| ERROR assigned_leaf_path: `$(local i)`
85-
//~| ERROR assigned_leaf_path: `$(local j)`
86-
//~| ERROR assigned_leaf_path: `$(local d1)`
87-
//~| ERROR assigned_leaf_path: `$(local d2)`
88-
//~| ERROR moved_leaf_path: `$(local d1)`
89-
//~| ERROR moved_leaf_path: `$(local d2)`
90-
//~| ERROR assigned_leaf_path: `$(local mut a).[]`
91-
//~| ERROR unmoved_fragment: `$(allbutone $(local mut a).[])`
92-
93-
// This test covers the case where the array contents have been all moved away, but
94-
// we still need to deal with new initializing writes into the array.
95-
*recv = a;
96-
a[i] = d1;
97-
a[j] = d2;
98-
}
99-
10047
pub fn main() { }

0 commit comments

Comments
 (0)