about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libstd/mutable.rs9
-rw-r--r--src/test/compile-fail/mut-cant-alias.rs18
-rw-r--r--src/test/compile-fail/mut-ptr-cant-outlive-ref.rs20
3 files changed, 47 insertions, 0 deletions
diff --git a/src/libstd/mutable.rs b/src/libstd/mutable.rs
index 98177b3cdf5..44efbc149c1 100644
--- a/src/libstd/mutable.rs
+++ b/src/libstd/mutable.rs
@@ -295,4 +295,13 @@ mod test {
         let _b = x.borrow();
         x.with_mut(|x| *x += 1);
     }
+
+    #[test]
+    #[should_fail]
+    fn discard_doesnt_unborrow() {
+        let x = Mut::new(0);
+        let _b = x.borrow();
+        let _ = _b;
+        let _b = x.borrow_mut();
+    }
 }
diff --git a/src/test/compile-fail/mut-cant-alias.rs b/src/test/compile-fail/mut-cant-alias.rs
new file mode 100644
index 00000000000..8e37f88af82
--- /dev/null
+++ b/src/test/compile-fail/mut-cant-alias.rs
@@ -0,0 +1,18 @@
+// Copyright 2013 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.
+
+use std::mutable::Mut;
+
+fn main() {
+    let m = Mut::new(0);
+    let mut b = m.borrow_mut();
+    let b1 = b.get();
+    let b2 = b.get(); //~ ERROR cannot borrow `b` as mutable more than once at a time
+}
diff --git a/src/test/compile-fail/mut-ptr-cant-outlive-ref.rs b/src/test/compile-fail/mut-ptr-cant-outlive-ref.rs
new file mode 100644
index 00000000000..0dbba87019a
--- /dev/null
+++ b/src/test/compile-fail/mut-ptr-cant-outlive-ref.rs
@@ -0,0 +1,20 @@
+// Copyright 2013 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.
+
+use std::mutable::Mut;
+
+fn main() {
+    let m = Mut::new(0);
+    let p;
+    {
+        let b = m.borrow();
+        p = b.get(); //~ ERROR borrowed value does not live long enough
+    }
+}