From f70abe8d07023bc58cac03a989ddbd37332fa10f Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 20 Nov 2018 11:33:46 +0100 Subject: [PATCH] Add sanity test for promotion and `const_let` --- src/test/ui/consts/promote_const_let.nll.stderr | 14 ++++++++++++++ src/test/ui/consts/promote_const_let.rs | 8 ++++++++ src/test/ui/consts/promote_const_let.stderr | 13 +++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/test/ui/consts/promote_const_let.nll.stderr create mode 100644 src/test/ui/consts/promote_const_let.rs create mode 100644 src/test/ui/consts/promote_const_let.stderr 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 000000000000..d8749bb5fd90 --- /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 000000000000..1ba406a957d2 --- /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 000000000000..6bbb7495fb0d --- /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`.