about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2018-08-06 12:17:39 +0200
committerNiko Matsakis <niko@alum.mit.edu>2018-08-06 09:00:35 -0400
commit3b4ed18d1c0cd0b33606cf2baeaaa64c67e587da (patch)
treee69fe33a0e4357471ba9c59aad1742f7e80183dc
parent67c96edce6a63dc02d567089788551598a2636f6 (diff)
downloadrust-3b4ed18d1c0cd0b33606cf2baeaaa64c67e587da.tar.gz
rust-3b4ed18d1c0cd0b33606cf2baeaaa64c67e587da.zip
add test case showing how previous attempt was unsound
-rw-r--r--src/test/ui/borrowck/issue-52713-bug.rs29
-rw-r--r--src/test/ui/borrowck/issue-52713-bug.stderr14
2 files changed, 43 insertions, 0 deletions
diff --git a/src/test/ui/borrowck/issue-52713-bug.rs b/src/test/ui/borrowck/issue-52713-bug.rs
new file mode 100644
index 00000000000..4ecba64b271
--- /dev/null
+++ b/src/test/ui/borrowck/issue-52713-bug.rs
@@ -0,0 +1,29 @@
+// Copyright 2014 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.
+
+// Regression test for a bug in #52713: this was an optimization for
+// computing liveness that wound up accidentally causing the program
+// below to be accepted.
+
+#![feature(nll)]
+
+fn foo<'a>(x: &'a mut u32) -> u32 {
+    let mut x = 22;
+    let y = &x;
+    if false {
+        return x;
+    }
+
+    x += 1; //~ ERROR
+    println!("{}", y);
+    return 0;
+}
+
+fn main() { }
diff --git a/src/test/ui/borrowck/issue-52713-bug.stderr b/src/test/ui/borrowck/issue-52713-bug.stderr
new file mode 100644
index 00000000000..7d9b57400dd
--- /dev/null
+++ b/src/test/ui/borrowck/issue-52713-bug.stderr
@@ -0,0 +1,14 @@
+error[E0506]: cannot assign to `x` because it is borrowed
+  --> $DIR/issue-52713-bug.rs:24:5
+   |
+LL |     let y = &x;
+   |             -- borrow of `x` occurs here
+...
+LL |     x += 1; //~ ERROR
+   |     ^^^^^^ assignment to borrowed `x` occurs here
+LL |     println!("{}", y);
+   |                    - borrow later used here
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0506`.