diff options
| author | Gary Guo <gary@garyguo.net> | 2021-10-03 23:14:33 +0100 |
|---|---|---|
| committer | Gary Guo <gary@garyguo.net> | 2021-11-07 04:00:34 +0000 |
| commit | ff055e2135574a0b795c0bc03144a89b54351af7 (patch) | |
| tree | ce737142c055aadbe4503c803c6bf664ec8373ef /src/test/ui/inline-const | |
| parent | 1d32b201707ce6327c0ab322c4e06d8e0367f563 (diff) | |
| download | rust-ff055e2135574a0b795c0bc03144a89b54351af7.tar.gz rust-ff055e2135574a0b795c0bc03144a89b54351af7.zip | |
Ensure closure requirements are proven for inline const
Diffstat (limited to 'src/test/ui/inline-const')
| -rw-r--r-- | src/test/ui/inline-const/const-expr-lifetime-err.rs | 30 | ||||
| -rw-r--r-- | src/test/ui/inline-const/const-expr-lifetime-err.stderr | 18 |
2 files changed, 48 insertions, 0 deletions
diff --git a/src/test/ui/inline-const/const-expr-lifetime-err.rs b/src/test/ui/inline-const/const-expr-lifetime-err.rs new file mode 100644 index 00000000000..e56cbc94038 --- /dev/null +++ b/src/test/ui/inline-const/const-expr-lifetime-err.rs @@ -0,0 +1,30 @@ +#![allow(incomplete_features)] +#![feature(const_mut_refs)] +#![feature(inline_const)] + +use std::marker::PhantomData; + +#[derive(PartialEq, Eq)] +pub struct InvariantRef<'a, T: ?Sized>(&'a T, PhantomData<&'a mut &'a T>); + +impl<'a, T: ?Sized> InvariantRef<'a, T> { + pub const fn new(r: &'a T) -> Self { + InvariantRef(r, PhantomData) + } +} + +impl<'a> InvariantRef<'a, ()> { + pub const NEW: Self = InvariantRef::new(&()); +} + +fn equate<T>(x: T, y: T){} + +fn foo<'a>() { + let y = (); + equate(InvariantRef::new(&y), const { InvariantRef::<'a>::NEW }); + //~^ ERROR `y` does not live long enough [E0597] +} + +fn main() { + foo(); +} diff --git a/src/test/ui/inline-const/const-expr-lifetime-err.stderr b/src/test/ui/inline-const/const-expr-lifetime-err.stderr new file mode 100644 index 00000000000..30ecd338a85 --- /dev/null +++ b/src/test/ui/inline-const/const-expr-lifetime-err.stderr @@ -0,0 +1,18 @@ +error[E0597]: `y` does not live long enough + --> $DIR/const-expr-lifetime-err.rs:24:30 + | +LL | fn foo<'a>() { + | -- lifetime `'a` defined here +LL | let y = (); +LL | equate(InvariantRef::new(&y), const { InvariantRef::<'a>::NEW }); + | ------------------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `y` is borrowed for `'a` +LL | +LL | } + | - `y` dropped here while still borrowed + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0597`. |
