about summary refs log tree commit diff
path: root/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs')
-rw-r--r--src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs b/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs
new file mode 100644
index 00000000000..3c01045369f
--- /dev/null
+++ b/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs
@@ -0,0 +1,31 @@
+#[allow(dead_code)];
+fn main() {
+    // Original borrow ends at end of function
+    let mut x = 1u;
+    let y = &mut x;
+    let z = &x; //~ ERROR cannot borrow
+}
+//~^ NOTE previous borrow ends here
+
+fn foo() {
+    match true {
+        true => {
+            // Original borrow ends at end of match arm
+            let mut x = 1u;
+            let y = &x;
+            let z = &mut x; //~ ERROR cannot borrow
+        }
+     //~^ NOTE previous borrow ends here
+        false => ()
+    }
+}
+
+fn bar() {
+    // Original borrow ends at end of closure
+    || {
+        let mut x = 1u;
+        let y = &mut x;
+        let z = &mut x; //~ ERROR cannot borrow
+    };
+ //~^ NOTE previous borrow ends here
+}