Skip to content

Commit

Permalink
Unit tests for gathering and reporting move-errors from mir-borrowck.
Browse files Browse the repository at this point in the history
This commit tests *just* the subset of the tests that were previously
ICE'ing and where now AST- and MIR-borrowck both match in terms of the
errors they report.

In other words: there remain *other* tests that previously ICE'd, and
now no longer ICE, but their remains a divergence between the errors
reported by AST-borrowck and by MIR-borrowck.
  • Loading branch information
pnkfelix committed Oct 4, 2017
1 parent 5a16ef4 commit 86ca5cf
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 13 deletions.
7 changes: 6 additions & 1 deletion src/test/compile-fail/borrowck/borrowck-fn-in-const-a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// revisions: ast mir
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir

// Check that we check fns appearing in constant declarations.
// Issue #22382.

const MOVE: fn(&String) -> String = {
fn broken(x: &String) -> String {
return *x //~ ERROR cannot move
return *x //[ast]~ ERROR cannot move out of borrowed content [E0507]
//[mir]~^ ERROR (Ast) [E0507]
//[mir]~| ERROR (Mir) [E0507]
}
broken
};
Expand Down
15 changes: 12 additions & 3 deletions src/test/compile-fail/borrowck/borrowck-move-in-irrefut-pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,28 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// revisions: ast mir
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir

fn with<F>(f: F) where F: FnOnce(&String) {}

fn arg_item(&_x: &String) {}
//~^ ERROR cannot move out of borrowed content
//[ast]~^ ERROR cannot move out of borrowed content [E0507]
//[mir]~^^ ERROR (Ast) [E0507]
//[mir]~| ERROR (Mir) [E0507]

fn arg_closure() {
with(|&_x| ())
//~^ ERROR cannot move out of borrowed content
//[ast]~^ ERROR cannot move out of borrowed content [E0507]
//[mir]~^^ ERROR (Ast) [E0507]
//[mir]~| ERROR (Mir) [E0507]
}

fn let_pat() {
let &_x = &"hi".to_string();
//~^ ERROR cannot move out of borrowed content
//[ast]~^ ERROR cannot move out of borrowed content [E0507]
//[mir]~^^ ERROR (Ast) [E0507]
//[mir]~| ERROR (Mir) [E0507]
}

pub fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// revisions: ast mir
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir

use std::rc::Rc;

pub fn main() {
let _x = Rc::new(vec![1, 2]).into_iter();
//~^ ERROR cannot move out of borrowed content
//[ast]~^ ERROR cannot move out of borrowed content [E0507]
//[mir]~^^ ERROR (Ast) [E0507]
//[mir]~| ERROR (Mir) [E0507]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// revisions: ast mir
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir

// Ensure that moves out of static items is forbidden

struct Foo {
Expand All @@ -22,5 +25,7 @@ fn test(f: Foo) {
}

fn main() {
test(BAR); //~ ERROR cannot move out of static item
test(BAR); //[ast]~ ERROR cannot move out of static item [E0507]
//[mir]~^ ERROR (Ast) [E0507]
//[mir]~| ERROR (Mir) [E0507]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// revisions: ast mir
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir

struct S {f:String}
impl Drop for S {
fn drop(&mut self) { println!("{}", self.f); }
Expand All @@ -16,17 +19,23 @@ impl Drop for S {
fn move_in_match() {
match (S {f:"foo".to_string()}) {
S {f:_s} => {}
//~^ ERROR cannot move out of type `S`, which implements the `Drop` trait
//[ast]~^ ERROR cannot move out of type `S`, which implements the `Drop` trait [E0509]
//[mir]~^^ ERROR (Ast) [E0509]
//[mir]~| ERROR (Mir) [E0509]
}
}

fn move_in_let() {
let S {f:_s} = S {f:"foo".to_string()};
//~^ ERROR cannot move out of type `S`, which implements the `Drop` trait
//[ast]~^ ERROR cannot move out of type `S`, which implements the `Drop` trait [E0509]
//[mir]~^^ ERROR (Ast) [E0509]
//[mir]~| ERROR (Mir) [E0509]
}

fn move_in_fn_arg(S {f:_s}: S) {
//~^ ERROR cannot move out of type `S`, which implements the `Drop` trait
//[ast]~^ ERROR cannot move out of type `S`, which implements the `Drop` trait [E0509]
//[mir]~^^ ERROR (Ast) [E0509]
//[mir]~| ERROR (Mir) [E0509]
}

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// revisions: ast mir
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir

// Issue 4691: Ensure that functional-struct-update can only copy, not
// move, when the struct implements Drop.

Expand All @@ -20,12 +23,16 @@ impl Drop for T { fn drop(&mut self) { } }

fn f(s0:S) {
let _s2 = S{a: 2, ..s0};
//~^ error: cannot move out of type `S`, which implements the `Drop` trait
//[ast]~^ error: cannot move out of type `S`, which implements the `Drop` trait
//[mir]~^^ ERROR (Ast) [E0509]
//[mir]~| ERROR (Mir) [E0509]
}

fn g(s0:T) {
let _s2 = T{a: 2, ..s0};
//~^ error: cannot move out of type `T`, which implements the `Drop` trait
//[ast]~^ error: cannot move out of type `T`, which implements the `Drop` trait
//[mir]~^^ ERROR (Ast) [E0509]
//[mir]~| ERROR (Mir) [E0509]
}

fn main() { }
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// revisions: ast mir
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir

// Regression test for #38520. Check that moves of `Foo` are not
// permitted as `Foo` is not copy (even in a static/const
// initializer).
Expand All @@ -21,8 +24,12 @@ const fn get(x: Foo) -> usize {
}

const X: Foo = Foo(22);
static Y: usize = get(*&X); //~ ERROR E0507
const Z: usize = get(*&X); //~ ERROR E0507
static Y: usize = get(*&X); //[ast]~ ERROR E0507
//[mir]~^ ERROR (Ast) [E0507]
//[mir]~| ERROR (Mir) [E0507]
const Z: usize = get(*&X); //[ast]~ ERROR E0507
//[mir]~^ ERROR (Ast) [E0507]
//[mir]~| ERROR (Mir) [E0507]

fn main() {
}

0 comments on commit 86ca5cf

Please sign in to comment.