]> git.lizzy.rs Git - rust.git/blob - tests/ui/impl-trait/nested-rpit-hrtb.rs
Rollup merge of #106799 - scottmcm:remove-unused-generics, r=cuviper
[rust.git] / tests / ui / impl-trait / nested-rpit-hrtb.rs
1 // Test the interaction between rested RPIT and HRTB.
2
3 trait Foo<'a> {
4     type Assoc;
5 }
6
7 impl Foo<'_> for () {
8     type Assoc = ();
9 }
10
11 // Alternative version of `Foo` whose impl uses `'a`.
12 trait Bar<'a> {
13     type Assoc;
14 }
15
16 impl<'a> Bar<'a> for () {
17     type Assoc = &'a ();
18 }
19
20 trait Qux<'a> {}
21
22 impl Qux<'_> for () {}
23
24 // This is not supported.
25 fn one_hrtb_outlives() -> impl for<'a> Foo<'a, Assoc = impl Sized + 'a> {}
26 //~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
27
28 // This is not supported.
29 fn one_hrtb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl Qux<'a>> {}
30 //~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
31
32 fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {}
33 //~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
34
35 fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {}
36 //~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
37
38 // This should resolve.
39 fn one_hrtb_mention_fn_trait_param<'b>() -> impl for<'a> Foo<'a, Assoc = impl Qux<'b>> {}
40
41 // This should resolve.
42 fn one_hrtb_mention_fn_outlives<'b>() -> impl for<'a> Foo<'a, Assoc = impl Sized + 'b> {}
43
44 // This should resolve.
45 fn one_hrtb_mention_fn_trait_param_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Qux<'b>> {}
46
47 // This should resolve.
48 fn one_hrtb_mention_fn_outlives_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'b> {}
49
50 // This should resolve.
51 fn two_htrb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl for<'b> Qux<'b>> {}
52
53 // `'b` is not in scope for the outlives bound.
54 fn two_htrb_outlives() -> impl for<'a> Foo<'a, Assoc = impl for<'b> Sized + 'b> {}
55 //~^ ERROR use of undeclared lifetime name `'b` [E0261]
56
57 // This should resolve.
58 fn two_htrb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Qux<'b>> {}
59
60 // `'b` is not in scope for the outlives bound.
61 fn two_htrb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Sized + 'b> {}
62 //~^ ERROR use of undeclared lifetime name `'b` [E0261]
63
64 fn main() {}