Skip to content

Commit

Permalink
Rollup merge of rust-lang#55801 - pnkfelix:update-box-insensitivity-t…
Browse files Browse the repository at this point in the history
…est-for-nll, r=davidtwco

NLL: Update box insensitivity test

This is just keeping one of our tests honest with respect to NLL, in two ways:

 1. Adds uses of borrows that would otherwise be too short to observe the error that we would have expected to see...
 2. ... I say "would have expected" because all of the errors in this file are part of the reversion of rust-lang/rfcs#130 that is attached to NLL (you can see more discussion of this here rust-lang#43234 (comment) )
  • Loading branch information
pietroalbini authored Nov 10, 2018
2 parents ff8ee96 + 9b6a568 commit 18195d4
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<isize>`, which does not implement the `Copy` trait
Expand All @@ -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<isize>`, which does not implement the `Copy` trait
Expand All @@ -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<isize>`, which does not implement the `Copy` trait
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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<isize>`, which does not implement the `Copy` trait
Expand All @@ -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<isize>`, which does not implement the `Copy` trait
Expand All @@ -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<isize>`, which does not implement the `Copy` trait
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/borrowck/borrowck-box-insensitivity.mir.stderr
Original file line number Diff line number Diff line change
@@ -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

125 changes: 64 additions & 61 deletions src/test/ui/borrowck/borrowck-box-insensitivity.rs
Original file line number Diff line number Diff line change
@@ -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<T>` should not
// be treated specially by the AST-borrowck.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// NLL goes back to treating `Box<T>` 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 {
Expand All @@ -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<isize>`
//~| 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<isize>`
//[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<isize>`
//~| 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<isize>`
//[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<isize>`
//~| 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<isize>`
//[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();
Expand All @@ -180,3 +180,6 @@ fn main() {
borrow_after_mut_borrow_nested();
mut_borrow_after_borrow_nested();
}

fn use_mut<T>(_: &mut T) { }
fn use_imm<T>(_: &T) { }

0 comments on commit 18195d4

Please sign in to comment.