summaryrefslogtreecommitdiffstats
path: root/tests/ui/traits/object/issue-44454-2.rs
blob: f5178bcdbe224011b134946f9120d52ce40dbcad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Taken from https://github.com/rust-lang/rust/issues/44454#issuecomment-1175925928

trait Trait<ARG: 'static>: 'static {
    type Assoc: AsRef<str>;
}

fn hr<T: ?Sized, ARG>(x: T::Assoc) -> Box<dyn AsRef<str> + 'static>
where
    T: Trait<ARG>
{
    Box::new(x)
}

fn extend_lt<'a>(x: &'a str) -> Box<dyn AsRef<str> + 'static> {
    type DynTrait = dyn for<'a> Trait<&'a str, Assoc = &'a str>;
    hr::<DynTrait, _>(x) //~ ERROR: borrowed data escapes outside of function
}

fn main() {
    let extended = extend_lt(&String::from("hello"));
    println!("{}", extended.as_ref().as_ref());
}