From 86ca5cf94241104c2a24d75f98784f65a40f7baa Mon Sep 17 00:00:00 2001
From: "Felix S. Klock II" <pnkfelix@pnkfx.org>
Date: Wed, 4 Oct 2017 13:29:55 +0200
Subject: [PATCH] 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.
---
 .../borrowck/borrowck-fn-in-const-a.rs            |  7 ++++++-
 .../borrowck/borrowck-move-in-irrefut-pat.rs      | 15 ++++++++++++---
 .../borrowck-move-out-of-overloaded-auto-deref.rs |  7 ++++++-
 .../borrowck/borrowck-move-out-of-static-item.rs  |  7 ++++++-
 .../borrowck-move-out-of-struct-with-dtor.rs      | 15 ++++++++++++---
 .../borrowck/borrowck-struct-update-with-dtor.rs  | 11 +++++++++--
 .../move-in-static-initializer-issue-38520.rs     | 11 +++++++++--
 7 files changed, 60 insertions(+), 13 deletions(-)

diff --git a/src/test/compile-fail/borrowck/borrowck-fn-in-const-a.rs b/src/test/compile-fail/borrowck/borrowck-fn-in-const-a.rs
index 3098807f272..fcdcf198c28 100644
--- a/src/test/compile-fail/borrowck/borrowck-fn-in-const-a.rs
+++ b/src/test/compile-fail/borrowck/borrowck-fn-in-const-a.rs
@@ -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
 };
diff --git a/src/test/compile-fail/borrowck/borrowck-move-in-irrefut-pat.rs b/src/test/compile-fail/borrowck/borrowck-move-in-irrefut-pat.rs
index ec505faf885..99b5ef794c2 100644
--- a/src/test/compile-fail/borrowck/borrowck-move-in-irrefut-pat.rs
+++ b/src/test/compile-fail/borrowck/borrowck-move-in-irrefut-pat.rs
@@ -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() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-move-out-of-overloaded-auto-deref.rs b/src/test/compile-fail/borrowck/borrowck-move-out-of-overloaded-auto-deref.rs
index bf4c7474136..c7e1ea1b758 100644
--- a/src/test/compile-fail/borrowck/borrowck-move-out-of-overloaded-auto-deref.rs
+++ b/src/test/compile-fail/borrowck/borrowck-move-out-of-overloaded-auto-deref.rs
@@ -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]
 }
diff --git a/src/test/compile-fail/borrowck/borrowck-move-out-of-static-item.rs b/src/test/compile-fail/borrowck/borrowck-move-out-of-static-item.rs
index 8b83b945fd1..9e8021fd108 100644
--- a/src/test/compile-fail/borrowck/borrowck-move-out-of-static-item.rs
+++ b/src/test/compile-fail/borrowck/borrowck-move-out-of-static-item.rs
@@ -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 {
@@ -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]
 }
diff --git a/src/test/compile-fail/borrowck/borrowck-move-out-of-struct-with-dtor.rs b/src/test/compile-fail/borrowck/borrowck-move-out-of-struct-with-dtor.rs
index 16302d276ce..982f31b1341 100644
--- a/src/test/compile-fail/borrowck/borrowck-move-out-of-struct-with-dtor.rs
+++ b/src/test/compile-fail/borrowck/borrowck-move-out-of-struct-with-dtor.rs
@@ -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); }
@@ -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() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-struct-update-with-dtor.rs b/src/test/compile-fail/borrowck/borrowck-struct-update-with-dtor.rs
index c364788a9cc..4a1828c6958 100644
--- a/src/test/compile-fail/borrowck/borrowck-struct-update-with-dtor.rs
+++ b/src/test/compile-fail/borrowck/borrowck-struct-update-with-dtor.rs
@@ -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.
 
@@ -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() { }
diff --git a/src/test/compile-fail/borrowck/move-in-static-initializer-issue-38520.rs b/src/test/compile-fail/borrowck/move-in-static-initializer-issue-38520.rs
index 3c1980e5b36..7f3120cc83e 100644
--- a/src/test/compile-fail/borrowck/move-in-static-initializer-issue-38520.rs
+++ b/src/test/compile-fail/borrowck/move-in-static-initializer-issue-38520.rs
@@ -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).
@@ -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() {
 }