]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/local-outlives-static-via-hrtb.rs
Rollup merge of #105216 - GuillaumeGomez:rm-unused-gui-test, r=notriddle
[rust.git] / src / test / ui / nll / local-outlives-static-via-hrtb.rs
1 // Test that we handle the case when a local variable is borrowed for `'static`
2 // due to an outlives constraint involving a region in an incompatible universe
3
4 pub trait Outlives<'this> {}
5
6 impl<'this, T> Outlives<'this> for T where T: 'this {}
7 trait Reference {
8     type AssociatedType;
9 }
10
11 impl<'a, T: 'a> Reference for &'a T {
12     type AssociatedType = &'a ();
13 }
14
15 fn assert_static_via_hrtb<G>(_: G) where for<'a> G: Outlives<'a> {}
16
17 fn assert_static_via_hrtb_with_assoc_type<T>(_: &'_ T)
18 where
19     for<'a> &'a T: Reference<AssociatedType = &'a ()>,
20 {}
21
22 fn main() {
23     let local = 0;
24     assert_static_via_hrtb(&local); //~ ERROR `local` does not live long enough
25     assert_static_via_hrtb_with_assoc_type(&&local); //~ ERROR `local` does not live long enough
26 }