Skip to content

Commit 86ca5cf

Browse files
committed
Unit tests for gathering and reporting move-errors from mir-borrowck.
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.
1 parent 5a16ef4 commit 86ca5cf

7 files changed

+60
-13
lines changed

src/test/compile-fail/borrowck/borrowck-fn-in-const-a.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// revisions: ast mir
12+
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
13+
1114
// Check that we check fns appearing in constant declarations.
1215
// Issue #22382.
1316

1417
const MOVE: fn(&String) -> String = {
1518
fn broken(x: &String) -> String {
16-
return *x //~ ERROR cannot move
19+
return *x //[ast]~ ERROR cannot move out of borrowed content [E0507]
20+
//[mir]~^ ERROR (Ast) [E0507]
21+
//[mir]~| ERROR (Mir) [E0507]
1722
}
1823
broken
1924
};

src/test/compile-fail/borrowck/borrowck-move-in-irrefut-pat.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,28 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// revisions: ast mir
12+
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
13+
1114
fn with<F>(f: F) where F: FnOnce(&String) {}
1215

1316
fn arg_item(&_x: &String) {}
14-
//~^ ERROR cannot move out of borrowed content
17+
//[ast]~^ ERROR cannot move out of borrowed content [E0507]
18+
//[mir]~^^ ERROR (Ast) [E0507]
19+
//[mir]~| ERROR (Mir) [E0507]
1520

1621
fn arg_closure() {
1722
with(|&_x| ())
18-
//~^ ERROR cannot move out of borrowed content
23+
//[ast]~^ ERROR cannot move out of borrowed content [E0507]
24+
//[mir]~^^ ERROR (Ast) [E0507]
25+
//[mir]~| ERROR (Mir) [E0507]
1926
}
2027

2128
fn let_pat() {
2229
let &_x = &"hi".to_string();
23-
//~^ ERROR cannot move out of borrowed content
30+
//[ast]~^ ERROR cannot move out of borrowed content [E0507]
31+
//[mir]~^^ ERROR (Ast) [E0507]
32+
//[mir]~| ERROR (Mir) [E0507]
2433
}
2534

2635
pub fn main() {}

src/test/compile-fail/borrowck/borrowck-move-out-of-overloaded-auto-deref.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// revisions: ast mir
12+
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
13+
1114
use std::rc::Rc;
1215

1316
pub fn main() {
1417
let _x = Rc::new(vec![1, 2]).into_iter();
15-
//~^ ERROR cannot move out of borrowed content
18+
//[ast]~^ ERROR cannot move out of borrowed content [E0507]
19+
//[mir]~^^ ERROR (Ast) [E0507]
20+
//[mir]~| ERROR (Mir) [E0507]
1621
}

src/test/compile-fail/borrowck/borrowck-move-out-of-static-item.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// revisions: ast mir
12+
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
13+
1114
// Ensure that moves out of static items is forbidden
1215

1316
struct Foo {
@@ -22,5 +25,7 @@ fn test(f: Foo) {
2225
}
2326

2427
fn main() {
25-
test(BAR); //~ ERROR cannot move out of static item
28+
test(BAR); //[ast]~ ERROR cannot move out of static item [E0507]
29+
//[mir]~^ ERROR (Ast) [E0507]
30+
//[mir]~| ERROR (Mir) [E0507]
2631
}

src/test/compile-fail/borrowck/borrowck-move-out-of-struct-with-dtor.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// revisions: ast mir
12+
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
13+
1114
struct S {f:String}
1215
impl Drop for S {
1316
fn drop(&mut self) { println!("{}", self.f); }
@@ -16,17 +19,23 @@ impl Drop for S {
1619
fn move_in_match() {
1720
match (S {f:"foo".to_string()}) {
1821
S {f:_s} => {}
19-
//~^ ERROR cannot move out of type `S`, which implements the `Drop` trait
22+
//[ast]~^ ERROR cannot move out of type `S`, which implements the `Drop` trait [E0509]
23+
//[mir]~^^ ERROR (Ast) [E0509]
24+
//[mir]~| ERROR (Mir) [E0509]
2025
}
2126
}
2227

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

2835
fn move_in_fn_arg(S {f:_s}: S) {
29-
//~^ ERROR cannot move out of type `S`, which implements the `Drop` trait
36+
//[ast]~^ ERROR cannot move out of type `S`, which implements the `Drop` trait [E0509]
37+
//[mir]~^^ ERROR (Ast) [E0509]
38+
//[mir]~| ERROR (Mir) [E0509]
3039
}
3140

3241
fn main() {}

src/test/compile-fail/borrowck/borrowck-struct-update-with-dtor.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// revisions: ast mir
12+
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
13+
1114
// Issue 4691: Ensure that functional-struct-update can only copy, not
1215
// move, when the struct implements Drop.
1316

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

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

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

3138
fn main() { }

src/test/compile-fail/borrowck/move-in-static-initializer-issue-38520.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// revisions: ast mir
12+
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
13+
1114
// Regression test for #38520. Check that moves of `Foo` are not
1215
// permitted as `Foo` is not copy (even in a static/const
1316
// initializer).
@@ -21,8 +24,12 @@ const fn get(x: Foo) -> usize {
2124
}
2225

2326
const X: Foo = Foo(22);
24-
static Y: usize = get(*&X); //~ ERROR E0507
25-
const Z: usize = get(*&X); //~ ERROR E0507
27+
static Y: usize = get(*&X); //[ast]~ ERROR E0507
28+
//[mir]~^ ERROR (Ast) [E0507]
29+
//[mir]~| ERROR (Mir) [E0507]
30+
const Z: usize = get(*&X); //[ast]~ ERROR E0507
31+
//[mir]~^ ERROR (Ast) [E0507]
32+
//[mir]~| ERROR (Mir) [E0507]
2633

2734
fn main() {
2835
}

0 commit comments

Comments
 (0)