]> git.lizzy.rs Git - rust.git/blob - tests/ui/type-alias-impl-trait/constrain_inputs_unsound.rs
Rollup merge of #106732 - durin42:dmitrig-arrayref-ctor, r=nikic
[rust.git] / tests / ui / type-alias-impl-trait / constrain_inputs_unsound.rs
1 #![feature(type_alias_impl_trait)]
2
3 trait Static: 'static {}
4 impl Static for () {}
5
6 type Gal<T> = impl Static;
7 fn _defining<T>() -> Gal<T> {}
8
9 trait Callable<Arg> { type Output; }
10
11 /// We can infer `<C as Callable<Arg>>::Output: 'static`,
12 /// because we know `C: 'static` and `Arg: 'static`,
13 fn box_str<C, Arg>(s: C::Output) -> Box<dyn AsRef<str> + 'static>
14 where
15     Arg: Static,
16     C: ?Sized + Callable<Arg> + 'static,
17     C::Output: AsRef<str>,
18 {
19     Box::new(s)
20 }
21
22 fn extend_lifetime(s: &str) -> Box<dyn AsRef<str> + 'static> {
23     type MalformedTy = dyn for<'a> Callable<Gal<&'a ()>, Output = &'a str>;
24     //~^ ERROR binding for associated type `Output` references lifetime `'a`
25     box_str::<MalformedTy, _>(s)
26 }
27
28 fn main() {
29     let extended = extend_lifetime(&String::from("hello"));
30     println!("{}", extended.as_ref().as_ref());
31 }