From 4583272bf5054e84c4c59ba3b9334a52cfcf5208 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 4 Feb 2015 12:25:25 +0100 Subject: [PATCH] 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.) --- .../borrowck-array-double-move.rs | 24 --------- .../borrowck-use-in-index-lvalue.rs | 4 +- .../borrowck-vec-pattern-move-tail.rs | 4 +- src/test/compile-fail/move-fragments-9.rs | 53 ------------------- 4 files changed, 5 insertions(+), 80 deletions(-) delete mode 100644 src/test/compile-fail/borrowck-array-double-move.rs diff --git a/src/test/compile-fail/borrowck-array-double-move.rs b/src/test/compile-fail/borrowck-array-double-move.rs deleted file mode 100644 index 3fb42b38e842..000000000000 --- a/src/test/compile-fail/borrowck-array-double-move.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(unknown_features)] -#![feature(box_syntax)] - -fn f() { - let mut a = [box 0, box 1]; - drop(a[0]); - a[1] = box 2; - drop(a[0]); //~ ERROR use of moved value: `a[..]` -} - -fn main() { - f(); -} - diff --git a/src/test/compile-fail/borrowck-use-in-index-lvalue.rs b/src/test/compile-fail/borrowck-use-in-index-lvalue.rs index 94c1d3a6a450..7291bcd2ce12 100644 --- a/src/test/compile-fail/borrowck-use-in-index-lvalue.rs +++ b/src/test/compile-fail/borrowck-use-in-index-lvalue.rs @@ -10,10 +10,10 @@ fn test() { let w: &mut [isize]; - w[5] = 0; //~ ERROR use of possibly uninitialized variable: `w` + w[5] = 0; //~ ERROR use of possibly uninitialized variable: `*w` let mut w: &mut [isize]; - w[5] = 0; //~ ERROR use of possibly uninitialized variable: `w` + w[5] = 0; //~ ERROR use of possibly uninitialized variable: `*w` } fn main() { test(); } diff --git a/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs b/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs index 5f58027af533..242a38440034 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs @@ -14,6 +14,8 @@ fn main() { [1, 2, tail..] => tail, _ => unreachable!() }; - a[0] = 0; //~ ERROR cannot assign to `a[..]` because it is borrowed + println!("t[0]: {}", t[0]); + a[2] = 0; //~ ERROR cannot assign to `a[..]` because it is borrowed + println!("t[0]: {}", t[0]); t[0]; } diff --git a/src/test/compile-fail/move-fragments-9.rs b/src/test/compile-fail/move-fragments-9.rs index d0eeebd02f80..426d5fa29a02 100644 --- a/src/test/compile-fail/move-fragments-9.rs +++ b/src/test/compile-fail/move-fragments-9.rs @@ -33,15 +33,6 @@ pub fn test_move_array_into_recv(a: [D; 3], recv: &mut [D; 3]) { *recv = a; } -#[rustc_move_fragments] -pub fn test_extract_array_elem(a: [D; 3], i: usize) -> D { - //~^ ERROR parent_of_fragments: `$(local a)` - //~| ERROR assigned_leaf_path: `$(local i)` - //~| ERROR moved_leaf_path: `$(local a).[]` - //~| ERROR unmoved_fragment: `$(allbutone $(local a).[])` - a[i] -} - #[rustc_move_fragments] pub fn test_overwrite_array_elem(mut a: [D; 3], i: usize, d: D) { //~^ 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) { a[i] = d; } -// FIXME (pnkfelix): Both test_move_array_then_overwrite_elem1 and -// test_move_array_then_overwrite_elem2 illustrate a behavior that -// we need to make illegal if we want to get rid of drop-flags. -// See RFC PR 320 for more discussion. - -#[rustc_move_fragments] -pub fn test_move_array_then_overwrite_elem1(mut a: [D; 3], i: usize, recv: &mut [D; 3], d: D) { - //~^ ERROR parent_of_fragments: `$(local mut a)` - //~| ERROR parent_of_fragments: `$(local recv)` - //~| ERROR assigned_leaf_path: `$(local recv).*` - //~| ERROR assigned_leaf_path: `$(local i)` - //~| ERROR assigned_leaf_path: `$(local d)` - //~| ERROR moved_leaf_path: `$(local d)` - //~| ERROR assigned_leaf_path: `$(local mut a).[]` - //~| ERROR unmoved_fragment: `$(allbutone $(local mut a).[])` - - // This test covers the case where the array contents have been all moved away, but - // we still need to deal with new initializing writes into the array. - *recv = a; - a[i] = d; -} - -#[rustc_move_fragments] -pub fn test_move_array_then_overwrite_elem2(mut a: [D; 3], i: usize, j: usize, - recv: &mut [D; 3], d1: D, d2: D) { - //~^^ ERROR parent_of_fragments: `$(local mut a)` - //~| ERROR parent_of_fragments: `$(local recv)` - //~| ERROR assigned_leaf_path: `$(local recv).*` - //~| ERROR assigned_leaf_path: `$(local i)` - //~| ERROR assigned_leaf_path: `$(local j)` - //~| ERROR assigned_leaf_path: `$(local d1)` - //~| ERROR assigned_leaf_path: `$(local d2)` - //~| ERROR moved_leaf_path: `$(local d1)` - //~| ERROR moved_leaf_path: `$(local d2)` - //~| ERROR assigned_leaf_path: `$(local mut a).[]` - //~| ERROR unmoved_fragment: `$(allbutone $(local mut a).[])` - - // This test covers the case where the array contents have been all moved away, but - // we still need to deal with new initializing writes into the array. - *recv = a; - a[i] = d1; - a[j] = d2; -} - pub fn main() { }