diff options
| author | Matthew Jasper <mjjasper1@gmail.com> | 2019-04-26 22:14:52 +0100 |
|---|---|---|
| committer | Matthew Jasper <mjjasper1@gmail.com> | 2019-04-26 22:14:52 +0100 |
| commit | a962274903e7947c5847dbaffbe6c554748e29b9 (patch) | |
| tree | f934e817a84f6db068cf1e1b00fe8365440951a0 /src/test | |
| parent | 597f432489f12a3f33419daa039ccef11a12c4fd (diff) | |
| download | rust-a962274903e7947c5847dbaffbe6c554748e29b9.tar.gz rust-a962274903e7947c5847dbaffbe6c554748e29b9.zip | |
Search for incompatible universes in borrow errors
If we have a borrow that has to live for `'static` we need to check for any regions in incompatible universes when trying to find the cause.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/nll/local-outlives-static-via-hrtb.rs | 26 | ||||
| -rw-r--r-- | src/test/ui/nll/local-outlives-static-via-hrtb.stderr | 26 |
2 files changed, 52 insertions, 0 deletions
diff --git a/src/test/ui/nll/local-outlives-static-via-hrtb.rs b/src/test/ui/nll/local-outlives-static-via-hrtb.rs new file mode 100644 index 00000000000..5f1f9b3a7f2 --- /dev/null +++ b/src/test/ui/nll/local-outlives-static-via-hrtb.rs @@ -0,0 +1,26 @@ +// Test that we handle the case when a local variable is borrowed for `'static` +// due to an outlives constraint involving a region in an incompatible universe + +pub trait Outlives<'this> {} + +impl<'this, T> Outlives<'this> for T where T: 'this {} +trait Reference { + type AssociatedType; +} + +impl<'a, T: 'a> Reference for &'a T { + type AssociatedType = &'a (); +} + +fn assert_static_via_hrtb<G>(_: G) where for<'a> G: Outlives<'a> {} + +fn assert_static_via_hrtb_with_assoc_type<T>(_: &'_ T) +where + for<'a> &'a T: Reference<AssociatedType = &'a ()>, +{} + +fn main() { + let local = 0; + assert_static_via_hrtb(&local); //~ ERROR `local` does not live long enough + assert_static_via_hrtb_with_assoc_type(&&local); //~ ERROR `local` does not live long enough +} diff --git a/src/test/ui/nll/local-outlives-static-via-hrtb.stderr b/src/test/ui/nll/local-outlives-static-via-hrtb.stderr new file mode 100644 index 00000000000..61009da49ff --- /dev/null +++ b/src/test/ui/nll/local-outlives-static-via-hrtb.stderr @@ -0,0 +1,26 @@ +error[E0597]: `local` does not live long enough + --> $DIR/local-outlives-static-via-hrtb.rs:24:28 + | +LL | assert_static_via_hrtb(&local); + | -----------------------^^^^^^- + | | | + | | borrowed value does not live long enough + | argument requires that `local` is borrowed for `'static` +LL | assert_static_via_hrtb_with_assoc_type(&&local); +LL | } + | - `local` dropped here while still borrowed + +error[E0597]: `local` does not live long enough + --> $DIR/local-outlives-static-via-hrtb.rs:25:45 + | +LL | assert_static_via_hrtb_with_assoc_type(&&local); + | ----------------------------------------^^^^^^- + | | | + | | borrowed value does not live long enough + | argument requires that `local` is borrowed for `'static` +LL | } + | - `local` dropped here while still borrowed + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0597`. |
