]> git.lizzy.rs Git - rust.git/blob - tests/ui/traits/object/issue-44454-2.rs
Auto merge of #105716 - chriswailes:ndk-update-redux, r=pietroalbini
[rust.git] / tests / ui / traits / object / issue-44454-2.rs
1 // Taken from https://github.com/rust-lang/rust/issues/44454#issuecomment-1175925928
2
3 trait Trait<ARG: 'static>: 'static {
4     type Assoc: AsRef<str>;
5 }
6
7 fn hr<T: ?Sized, ARG>(x: T::Assoc) -> Box<dyn AsRef<str> + 'static>
8 where
9     T: Trait<ARG>
10 {
11     Box::new(x)
12 }
13
14 fn extend_lt<'a>(x: &'a str) -> Box<dyn AsRef<str> + 'static> {
15     type DynTrait = dyn for<'a> Trait<&'a str, Assoc = &'a str>;
16     hr::<DynTrait, _>(x) //~ ERROR: borrowed data escapes outside of function
17 }
18
19 fn main() {
20     let extended = extend_lt(&String::from("hello"));
21     println!("{}", extended.as_ref().as_ref());
22 }