diff --git a/src/test/ui/borrowck/borrowck-box-insensitivity.stderr b/src/test/ui/borrowck/borrowck-box-insensitivity.ast.stderr similarity index 81% rename from src/test/ui/borrowck/borrowck-box-insensitivity.stderr rename to src/test/ui/borrowck/borrowck-box-insensitivity.ast.stderr index 5bf1fc08178..95b26a5724a 100644 --- a/src/test/ui/borrowck/borrowck-box-insensitivity.stderr +++ b/src/test/ui/borrowck/borrowck-box-insensitivity.ast.stderr @@ -3,8 +3,8 @@ error[E0382]: use of moved value: `a` | LL | let _x = a.x; | -- value moved here -LL | //~^ value moved here -LL | let _y = a.y; //~ ERROR use of moved +LL | //[ast]~^ value moved here +LL | let _y = a.y; //[ast]~ ERROR use of moved | ^^ value used here after move | = note: move occurs because `a.x` has type `std::boxed::Box`, which does not implement the `Copy` trait @@ -14,8 +14,8 @@ error[E0382]: use of moved value: `a` | LL | let _x = a.x; | -- value moved here -LL | //~^ value moved here -LL | let _y = a.y; //~ ERROR use of moved +LL | //[ast]~^ value moved here +LL | let _y = a.y; //[ast]~ ERROR use of moved | ^^ value used here after move | = note: move occurs because `a.x` has type `std::boxed::Box`, which does not implement the `Copy` trait @@ -25,8 +25,8 @@ error[E0382]: use of moved value: `a` | LL | let _x = a.x; | -- value moved here -LL | //~^ value moved here -LL | let _y = &a.y; //~ ERROR use of moved +LL | //[ast]~^ value moved here +LL | let _y = &a.y; //[ast]~ ERROR use of moved | ^^^ value used here after move | = note: move occurs because `a.x` has type `std::boxed::Box`, which does not implement the `Copy` trait @@ -44,7 +44,7 @@ error[E0503]: cannot use `a.y` because it was mutably borrowed | LL | let _x = &mut a.x; | --- borrow of `a.x` occurs here -LL | let _y = a.y; //~ ERROR cannot use +LL | let _y = a.y; //[ast]~ ERROR cannot use | ^^ use of borrowed `a.x` error[E0505]: cannot move out of `a.y` because it is borrowed @@ -60,9 +60,9 @@ error[E0502]: cannot borrow `a` (via `a.y`) as immutable because `a` is also bor | LL | let _x = &mut a.x; | --- mutable borrow occurs here (via `a.x`) -LL | let _y = &a.y; //~ ERROR cannot borrow +LL | let _y = &a.y; //[ast]~ ERROR cannot borrow | ^^^ immutable borrow occurs here (via `a.y`) -LL | //~^ immutable borrow occurs here (via `a.y`) +... LL | } | - mutable borrow ends here @@ -71,9 +71,9 @@ error[E0502]: cannot borrow `a` (via `a.y`) as mutable because `a` is also borro | LL | let _x = &a.x; | --- immutable borrow occurs here (via `a.x`) -LL | let _y = &mut a.y; //~ ERROR cannot borrow +LL | let _y = &mut a.y; //[ast]~ ERROR cannot borrow | ^^^ mutable borrow occurs here (via `a.y`) -LL | //~^ mutable borrow occurs here (via `a.y`) +... LL | } | - immutable borrow ends here @@ -82,8 +82,8 @@ error[E0382]: use of collaterally moved value: `a.y` | LL | let _x = a.x.x; | -- value moved here -LL | //~^ value moved here -LL | let _y = a.y; //~ ERROR use of collaterally moved +LL | //[ast]~^ value moved here +LL | let _y = a.y; //[ast]~ ERROR use of collaterally moved | ^^ value used here after move | = note: move occurs because `a.x.x` has type `std::boxed::Box`, which does not implement the `Copy` trait @@ -93,8 +93,8 @@ error[E0382]: use of collaterally moved value: `a.y` | LL | let _x = a.x.x; | -- value moved here -LL | //~^ value moved here -LL | let _y = a.y; //~ ERROR use of collaterally moved +LL | //[ast]~^ value moved here +LL | let _y = a.y; //[ast]~ ERROR use of collaterally moved | ^^ value used here after move | = note: move occurs because `a.x.x` has type `std::boxed::Box`, which does not implement the `Copy` trait @@ -104,8 +104,8 @@ error[E0382]: use of collaterally moved value: `a.y` | LL | let _x = a.x.x; | -- value moved here -LL | //~^ value moved here -LL | let _y = &a.y; //~ ERROR use of collaterally moved +LL | //[ast]~^ value moved here +LL | let _y = &a.y; //[ast]~ ERROR use of collaterally moved | ^^^ value used here after move | = note: move occurs because `a.x.x` has type `std::boxed::Box`, which does not implement the `Copy` trait @@ -115,7 +115,7 @@ error[E0505]: cannot move out of `a.y` because it is borrowed | LL | let _x = &a.x.x; | ----- borrow of `a.x.x` occurs here -LL | //~^ borrow of `a.x.x` occurs here +LL | //[ast]~^ borrow of `a.x.x` occurs here LL | let _y = a.y; | ^^ move out of `a.y` occurs here @@ -124,7 +124,7 @@ error[E0503]: cannot use `a.y` because it was mutably borrowed | LL | let _x = &mut a.x.x; | ----- borrow of `a.x.x` occurs here -LL | let _y = a.y; //~ ERROR cannot use +LL | let _y = a.y; //[ast]~ ERROR cannot use | ^^ use of borrowed `a.x.x` error[E0505]: cannot move out of `a.y` because it is borrowed @@ -140,10 +140,10 @@ error[E0502]: cannot borrow `a.y` as immutable because `a.x.x` is also borrowed | LL | let _x = &mut a.x.x; | ----- mutable borrow occurs here -LL | //~^ mutable borrow occurs here -LL | let _y = &a.y; //~ ERROR cannot borrow +LL | //[ast]~^ mutable borrow occurs here +LL | let _y = &a.y; //[ast]~ ERROR cannot borrow | ^^^ immutable borrow occurs here -LL | //~^ immutable borrow occurs here +... LL | } | - mutable borrow ends here @@ -152,10 +152,10 @@ error[E0502]: cannot borrow `a.y` as mutable because `a.x.x` is also borrowed as | LL | let _x = &a.x.x; | ----- immutable borrow occurs here -LL | //~^ immutable borrow occurs here -LL | let _y = &mut a.y; //~ ERROR cannot borrow +LL | //[ast]~^ immutable borrow occurs here +LL | let _y = &mut a.y; //[ast]~ ERROR cannot borrow | ^^^ mutable borrow occurs here -LL | //~^ mutable borrow occurs here +... LL | } | - immutable borrow ends here diff --git a/src/test/ui/borrowck/borrowck-box-insensitivity.mir.stderr b/src/test/ui/borrowck/borrowck-box-insensitivity.mir.stderr new file mode 100644 index 00000000000..171e992e8a6 --- /dev/null +++ b/src/test/ui/borrowck/borrowck-box-insensitivity.mir.stderr @@ -0,0 +1,14 @@ +error: compilation successful + --> $DIR/borrowck-box-insensitivity.rs:160:1 + | +LL | / fn main() { //[mir]~ ERROR compilation successful +LL | | copy_after_move(); +LL | | move_after_move(); +LL | | borrow_after_move(); +... | +LL | | mut_borrow_after_borrow_nested(); +LL | | } + | |_^ + +error: aborting due to previous error + diff --git a/src/test/ui/borrowck/borrowck-box-insensitivity.rs b/src/test/ui/borrowck/borrowck-box-insensitivity.rs index eabb8d7bca3..2af97a9fc1d 100644 --- a/src/test/ui/borrowck/borrowck-box-insensitivity.rs +++ b/src/test/ui/borrowck/borrowck-box-insensitivity.rs @@ -1,13 +1,13 @@ -// 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. +// This test is an artifact of the old policy that `Box` should not +// be treated specially by the AST-borrowck. // -// 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. +// NLL goes back to treating `Box` specially (namely, knowing that +// it uniquely owns the data it holds). See rust-lang/rfcs#130. +// revisions: ast mir +//[ast] compile-flags: -Z borrowck=ast +//[mir] compile-flags: -Z borrowck=mir +// ignore-compare-mode-nll #![feature(box_syntax, rustc_attrs)] struct A { @@ -33,131 +33,131 @@ struct D { fn copy_after_move() { let a: Box<_> = box A { x: box 0, y: 1 }; let _x = a.x; - //~^ value moved here - let _y = a.y; //~ ERROR use of moved - //~^ move occurs because `a.x` has type `std::boxed::Box` - //~| value used here after move + //[ast]~^ value moved here + let _y = a.y; //[ast]~ ERROR use of moved + //[ast]~^ move occurs because `a.x` has type `std::boxed::Box` + //[ast]~| value used here after move } fn move_after_move() { let a: Box<_> = box B { x: box 0, y: box 1 }; let _x = a.x; - //~^ value moved here - let _y = a.y; //~ ERROR use of moved - //~^ move occurs because `a.x` has type `std::boxed::Box` - //~| value used here after move + //[ast]~^ value moved here + let _y = a.y; //[ast]~ ERROR use of moved + //[ast]~^ move occurs because `a.x` has type `std::boxed::Box` + //[ast]~| value used here after move } fn borrow_after_move() { let a: Box<_> = box A { x: box 0, y: 1 }; let _x = a.x; - //~^ value moved here - let _y = &a.y; //~ ERROR use of moved - //~^ move occurs because `a.x` has type `std::boxed::Box` - //~| value used here after move + //[ast]~^ value moved here + let _y = &a.y; //[ast]~ ERROR use of moved + //[ast]~^ move occurs because `a.x` has type `std::boxed::Box` + //[ast]~| value used here after move } fn move_after_borrow() { let a: Box<_> = box B { x: box 0, y: box 1 }; let _x = &a.x; let _y = a.y; - //~^ ERROR cannot move - //~| move out of + //[ast]~^ ERROR cannot move + //[ast]~| move out of + use_imm(_x); } - fn copy_after_mut_borrow() { let mut a: Box<_> = box A { x: box 0, y: 1 }; let _x = &mut a.x; - let _y = a.y; //~ ERROR cannot use + let _y = a.y; //[ast]~ ERROR cannot use + use_mut(_x); } - fn move_after_mut_borrow() { let mut a: Box<_> = box B { x: box 0, y: box 1 }; let _x = &mut a.x; let _y = a.y; - //~^ ERROR cannot move - //~| move out of + //[ast]~^ ERROR cannot move + //[ast]~| move out of + use_mut(_x); } - fn borrow_after_mut_borrow() { let mut a: Box<_> = box A { x: box 0, y: 1 }; let _x = &mut a.x; - let _y = &a.y; //~ ERROR cannot borrow - //~^ immutable borrow occurs here (via `a.y`) + let _y = &a.y; //[ast]~ ERROR cannot borrow + //[ast]~^ immutable borrow occurs here (via `a.y`) + use_mut(_x); } - fn mut_borrow_after_borrow() { let mut a: Box<_> = box A { x: box 0, y: 1 }; let _x = &a.x; - let _y = &mut a.y; //~ ERROR cannot borrow - //~^ mutable borrow occurs here (via `a.y`) + let _y = &mut a.y; //[ast]~ ERROR cannot borrow + //[ast]~^ mutable borrow occurs here (via `a.y`) + use_imm(_x); } - fn copy_after_move_nested() { let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; let _x = a.x.x; - //~^ value moved here - let _y = a.y; //~ ERROR use of collaterally moved - //~| value used here after move + //[ast]~^ value moved here + let _y = a.y; //[ast]~ ERROR use of collaterally moved + //[ast]~| value used here after move } fn move_after_move_nested() { let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 }; let _x = a.x.x; - //~^ value moved here - let _y = a.y; //~ ERROR use of collaterally moved - //~| value used here after move + //[ast]~^ value moved here + let _y = a.y; //[ast]~ ERROR use of collaterally moved + //[ast]~| value used here after move } fn borrow_after_move_nested() { let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; let _x = a.x.x; - //~^ value moved here - let _y = &a.y; //~ ERROR use of collaterally moved - //~| value used here after move + //[ast]~^ value moved here + let _y = &a.y; //[ast]~ ERROR use of collaterally moved + //[ast]~| value used here after move } fn move_after_borrow_nested() { let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 }; let _x = &a.x.x; - //~^ borrow of `a.x.x` occurs here + //[ast]~^ borrow of `a.x.x` occurs here let _y = a.y; - //~^ ERROR cannot move - //~| move out of + //[ast]~^ ERROR cannot move + //[ast]~| move out of + use_imm(_x); } - fn copy_after_mut_borrow_nested() { let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; let _x = &mut a.x.x; - let _y = a.y; //~ ERROR cannot use + let _y = a.y; //[ast]~ ERROR cannot use + use_mut(_x); } - fn move_after_mut_borrow_nested() { let mut a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 }; let _x = &mut a.x.x; let _y = a.y; - //~^ ERROR cannot move - //~| move out of + //[ast]~^ ERROR cannot move + //[ast]~| move out of + use_mut(_x); } - fn borrow_after_mut_borrow_nested() { let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; let _x = &mut a.x.x; - //~^ mutable borrow occurs here - let _y = &a.y; //~ ERROR cannot borrow - //~^ immutable borrow occurs here + //[ast]~^ mutable borrow occurs here + let _y = &a.y; //[ast]~ ERROR cannot borrow + //[ast]~^ immutable borrow occurs here + use_mut(_x); } - fn mut_borrow_after_borrow_nested() { let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; let _x = &a.x.x; - //~^ immutable borrow occurs here - let _y = &mut a.y; //~ ERROR cannot borrow - //~^ mutable borrow occurs here + //[ast]~^ immutable borrow occurs here + let _y = &mut a.y; //[ast]~ ERROR cannot borrow + //[ast]~^ mutable borrow occurs here + use_imm(_x); } - #[rustc_error] -fn main() { +fn main() { //[mir]~ ERROR compilation successful copy_after_move(); move_after_move(); borrow_after_move(); @@ -180,3 +180,6 @@ fn main() { borrow_after_mut_borrow_nested(); mut_borrow_after_borrow_nested(); } + +fn use_mut(_: &mut T) { } +fn use_imm(_: &T) { }