]> git.lizzy.rs Git - rust.git/blob - src/test/ui/impl-trait/bound-normalization-pass.rs
Allow combining -Cprofile-generate and -Cpanic=unwind when targeting
[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(min_type_alias_impl_trait)]
8 #![feature(impl_trait_in_bindings)]
9 //~^ WARNING the feature `impl_trait_in_bindings` is incomplete
10
11 // See issue 60414
12
13 // Reduction to `impl Trait`
14
15 struct Foo<T>(T);
16
17 trait FooLike { type Output; }
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 // Reduction using `impl Trait` in bindings
63
64 mod impl_trait_in_bindings {
65     struct Foo;
66
67     trait FooLike { type Output; }
68
69     impl FooLike for Foo {
70         type Output = u32;
71     }
72
73     trait Trait {
74         type Assoc;
75     }
76
77     fn foo<T: Trait<Assoc=u32>>() {
78         let _: impl FooLike<Output=T::Assoc> = Foo;
79     }
80 }
81
82 // The same applied to `type Foo = impl Bar`s
83
84 mod opaque_types {
85     trait Implemented {
86         type Assoc;
87     }
88     impl<T> Implemented for T {
89         type Assoc = u8;
90     }
91
92     trait Trait {
93         type Out;
94     }
95
96     impl Trait for () {
97         type Out = u8;
98     }
99
100     type Ex = impl Trait<Out = <() as Implemented>::Assoc>;
101
102     fn define() -> Ex {
103         ()
104     }
105 }
106
107 fn main() {}