File: local-outlives-static-via-hrtb.rs

package info (click to toggle)
rustc 1.70.0%2Bdfsg1-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 722,120 kB
  • sloc: xml: 147,962; javascript: 10,210; sh: 8,590; python: 8,220; ansic: 5,901; cpp: 4,635; makefile: 4,001; asm: 2,856
file content (26 lines) | stat: -rw-r--r-- 766 bytes parent folder | download | duplicates (25)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
}