about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2018-11-20 11:33:46 +0100
committerOliver Scherer <github35764891676564198441@oli-obk.de>2018-11-20 11:33:46 +0100
commitf70abe8d07023bc58cac03a989ddbd37332fa10f (patch)
treedfac21d53cbcb7302325d2c7704f51338c6b1f81
parent6bcb0d6152e0b817da7af23bdb2abf13a8b2db43 (diff)
downloadrust-f70abe8d07023bc58cac03a989ddbd37332fa10f.tar.gz
rust-f70abe8d07023bc58cac03a989ddbd37332fa10f.zip
Add sanity test for promotion and `const_let`
-rw-r--r--src/test/ui/consts/promote_const_let.nll.stderr14
-rw-r--r--src/test/ui/consts/promote_const_let.rs8
-rw-r--r--src/test/ui/consts/promote_const_let.stderr13
3 files changed, 35 insertions, 0 deletions
diff --git a/src/test/ui/consts/promote_const_let.nll.stderr b/src/test/ui/consts/promote_const_let.nll.stderr
new file mode 100644
index 00000000000..d8749bb5fd9
--- /dev/null
+++ b/src/test/ui/consts/promote_const_let.nll.stderr
@@ -0,0 +1,14 @@
+error[E0597]: `y` does not live long enough
+  --> $DIR/promote_const_let.rs:6:9
+   |
+LL |     let x: &'static u32 = {
+   |            ------------ type annotation requires that `y` is borrowed for `'static`
+LL |         let y = 42;
+LL |         &y //~ ERROR does not live long enough
+   |         ^^ borrowed value does not live long enough
+LL |     };
+   |     - `y` dropped here while still borrowed
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0597`.
diff --git a/src/test/ui/consts/promote_const_let.rs b/src/test/ui/consts/promote_const_let.rs
new file mode 100644
index 00000000000..1ba406a957d
--- /dev/null
+++ b/src/test/ui/consts/promote_const_let.rs
@@ -0,0 +1,8 @@
+#![feature(const_let)]
+
+fn main() {
+    let x: &'static u32 = {
+        let y = 42;
+        &y //~ ERROR does not live long enough
+    };
+}
\ No newline at end of file
diff --git a/src/test/ui/consts/promote_const_let.stderr b/src/test/ui/consts/promote_const_let.stderr
new file mode 100644
index 00000000000..6bbb7495fb0
--- /dev/null
+++ b/src/test/ui/consts/promote_const_let.stderr
@@ -0,0 +1,13 @@
+error[E0597]: `y` does not live long enough
+  --> $DIR/promote_const_let.rs:6:10
+   |
+LL |         &y //~ ERROR does not live long enough
+   |          ^ borrowed value does not live long enough
+LL |     };
+   |     - borrowed value only lives until here
+   |
+   = note: borrowed value must be valid for the static lifetime...
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0597`.