about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorDavid Wood <david@davidtw.co>2018-12-06 15:47:30 +0100
committerDavid Wood <david@davidtw.co>2018-12-06 15:47:30 +0100
commit1149c58bb8020338ea5f3065af0a3342d42a31fa (patch)
tree401738a87e379066d21af97b5cc4058017a3a69c /src/test/ui
parent77a6a61f066af3dd693d8527a8a1bf5a446d295c (diff)
downloadrust-1149c58bb8020338ea5f3065af0a3342d42a31fa.tar.gz
rust-1149c58bb8020338ea5f3065af0a3342d42a31fa.zip
Add test for #46589.
This commit adds the test for writing into a projection of a local to
confirm there are no remaining borrows.
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/nll/issue-46589.rs38
-rw-r--r--src/test/ui/nll/issue-46589.stderr28
2 files changed, 66 insertions, 0 deletions
diff --git a/src/test/ui/nll/issue-46589.rs b/src/test/ui/nll/issue-46589.rs
new file mode 100644
index 00000000000..0099e44ec38
--- /dev/null
+++ b/src/test/ui/nll/issue-46589.rs
@@ -0,0 +1,38 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// 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.
+
+#![feature(nll)]
+
+struct Foo;
+
+impl Foo {
+    fn get_self(&mut self) -> Option<&mut Self> {
+        Some(self)
+    }
+
+    fn new_self(&mut self) -> &mut Self {
+        self
+    }
+
+    fn trigger_bug(&mut self) {
+        let other = &mut (&mut *self);
+
+        *other = match (*other).get_self() {
+            Some(s) => s,
+            None => (*other).new_self()
+            //~^ ERROR cannot borrow `**other` as mutable more than once at a time [E0499]
+        };
+
+        let c = other;
+        //~^ ERROR cannot move out of `other` because it is borrowed [E0505]
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/nll/issue-46589.stderr b/src/test/ui/nll/issue-46589.stderr
new file mode 100644
index 00000000000..ef656912b0f
--- /dev/null
+++ b/src/test/ui/nll/issue-46589.stderr
@@ -0,0 +1,28 @@
+error[E0499]: cannot borrow `**other` as mutable more than once at a time
+  --> $DIR/issue-46589.rs:29:21
+   |
+LL |         *other = match (*other).get_self() {
+   |                        -------- first mutable borrow occurs here
+LL |             Some(s) => s,
+LL |             None => (*other).new_self()
+   |                     ^^^^^^^^
+   |                     |
+   |                     second mutable borrow occurs here
+   |                     first borrow later used here
+
+error[E0505]: cannot move out of `other` because it is borrowed
+  --> $DIR/issue-46589.rs:33:17
+   |
+LL |         *other = match (*other).get_self() {
+   |                        -------- borrow of `**other` occurs here
+...
+LL |         let c = other;
+   |                 ^^^^^
+   |                 |
+   |                 move out of `other` occurs here
+   |                 borrow later used here
+
+error: aborting due to 2 previous errors
+
+Some errors occurred: E0499, E0505.
+For more information about an error, try `rustc --explain E0499`.