]> git.lizzy.rs Git - rust.git/blob - tests/ui/type-alias-impl-trait/implied_bounds.rs
Rollup merge of #106323 - starkat99:stabilize-f16c_target_feature, r=petrochenkov
[rust.git] / tests / ui / type-alias-impl-trait / implied_bounds.rs
1 #![feature(type_alias_impl_trait)]
2
3 type WithLifetime<'a> = impl Equals<SelfType = ()>;
4 fn _defining_use<'a>() -> WithLifetime<'a> {}
5
6 trait Convert<'a> {
7     type Witness;
8     fn convert<'b, T: ?Sized>(_proof: &'b Self::Witness, x: &'a T) -> &'b T;
9 }
10
11 impl<'a> Convert<'a> for () {
12     type Witness = WithLifetime<'a>;
13
14     fn convert<'b, T: ?Sized>(_proof: &'b WithLifetime<'a>, x: &'a T) -> &'b T {
15         // compiler used to think it gets to assume 'a: 'b here because
16         // of the `&'b WithLifetime<'a>` argument
17         x
18         //~^ ERROR lifetime may not live long enough
19     }
20 }
21
22 fn extend_lifetime<'a, 'b, T: ?Sized>(x: &'a T) -> &'b T {
23     WithLifetime::<'a>::convert_helper::<(), T>(&(), x)
24 }
25
26 trait Equals {
27     type SelfType;
28     fn convert_helper<'a, 'b, W: Convert<'a, Witness = Self>, T: ?Sized>(
29         proof: &'b Self::SelfType,
30         x: &'a T,
31     ) -> &'b T;
32 }
33
34 impl<S> Equals for S {
35     type SelfType = Self;
36     fn convert_helper<'a, 'b, W: Convert<'a, Witness = Self>, T: ?Sized>(
37         proof: &'b Self,
38         x: &'a T,
39     ) -> &'b T {
40         W::convert(proof, x)
41     }
42 }
43
44 fn main() {
45     let r;
46     {
47         let x = String::from("Hello World?");
48         r = extend_lifetime(&x);
49     }
50     println!("{}", r);
51 }