]> git.lizzy.rs Git - rust.git/blob - src/test/ui/impl-trait/bound-normalization-pass.rs
Rollup merge of #103159 - cuviper:check_pow-final-try_opt, r=Mark-Simulacrum
[rust.git] / src / test / ui / impl-trait / bound-normalization-pass.rs
1 // check-pass
2 // edition:2018
3 // revisions: default sa
4 //[sa] compile-flags: -Z save-analysis
5 //-^ To make this the regression test for #75962.
6
7 #![feature(type_alias_impl_trait)]
8
9 // See issue 60414
10
11 // Reduction to `impl Trait`
12
13 struct Foo<T>(T);
14
15 trait FooLike {
16     type Output;
17 }
18
19 impl<T> FooLike for Foo<T> {
20     type Output = T;
21 }
22
23 mod impl_trait {
24     use super::*;
25
26     trait Trait {
27         type Assoc;
28     }
29
30     /// `T::Assoc` should be normalized to `()` here.
31     fn foo_pass<T: Trait<Assoc = ()>>() -> impl FooLike<Output = T::Assoc> {
32         Foo(())
33     }
34 }
35
36 // Same with lifetimes in the trait
37
38 mod lifetimes {
39     use super::*;
40
41     trait Trait<'a> {
42         type Assoc;
43     }
44
45     /// Like above.
46     ///
47     /// FIXME(#51525) -- the shorter notation `T::Assoc` winds up referencing `'static` here
48     fn foo2_pass<'a, T: Trait<'a, Assoc = ()> + 'a>()
49     -> impl FooLike<Output = <T as Trait<'a>>::Assoc> + 'a {
50         Foo(())
51     }
52
53     /// Normalization to type containing bound region.
54     ///
55     /// FIXME(#51525) -- the shorter notation `T::Assoc` winds up referencing `'static` here
56     fn foo2_pass2<'a, T: Trait<'a, Assoc = &'a ()> + 'a>()
57     -> impl FooLike<Output = <T as Trait<'a>>::Assoc> + 'a {
58         Foo(&())
59     }
60 }
61
62 // The same applied to `type Foo = impl Bar`s
63
64 mod opaque_types {
65     trait Implemented {
66         type Assoc;
67     }
68     impl<T> Implemented for T {
69         type Assoc = u8;
70     }
71
72     trait Trait {
73         type Out;
74     }
75
76     impl Trait for () {
77         type Out = u8;
78     }
79
80     type Ex = impl Trait<Out = <() as Implemented>::Assoc>;
81
82     fn define() -> Ex {
83         ()
84     }
85 }
86
87 fn main() {}