Skip to content

Commit 872f09c

Browse files
committed
Add a test with both passing and erroneous cases.
1 parent b276b65 commit 872f09c

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 pass.
39+
fn one_hrtb_mention_fn_trait_param<'b>() -> impl for<'a> Foo<'a, Assoc = impl Qux<'b>> {}
40+
41+
// This should pass.
42+
fn one_hrtb_mention_fn_outlives<'b>() -> impl for<'a> Foo<'a, Assoc = impl Sized + 'b> {}
43+
44+
// This should pass.
45+
fn one_hrtb_mention_fn_trait_param_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Qux<'b>> {}
46+
47+
// This should pass.
48+
fn one_hrtb_mention_fn_outlives_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'b> {}
49+
50+
// This should pass.
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 pass.
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() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
error[E0261]: use of undeclared lifetime name `'b`
2+
--> $DIR/nested-rpit-hrtb.rs:54:77
3+
|
4+
LL | fn two_htrb_outlives() -> impl for<'a> Foo<'a, Assoc = impl for<'b> Sized + 'b> {}
5+
| ^^ undeclared lifetime
6+
|
7+
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
8+
help: consider making the bound lifetime-generic with a new `'b` lifetime
9+
|
10+
LL | fn two_htrb_outlives() -> impl for<'b, 'a> Foo<'a, Assoc = impl for<'b> Sized + 'b> {}
11+
| +++
12+
help: consider introducing lifetime `'b` here
13+
|
14+
LL | fn two_htrb_outlives<'b>() -> impl for<'a> Foo<'a, Assoc = impl for<'b> Sized + 'b> {}
15+
| ++++
16+
17+
error[E0261]: use of undeclared lifetime name `'b`
18+
--> $DIR/nested-rpit-hrtb.rs:61:82
19+
|
20+
LL | fn two_htrb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Sized + 'b> {}
21+
| ^^ undeclared lifetime
22+
|
23+
help: consider making the bound lifetime-generic with a new `'b` lifetime
24+
|
25+
LL | fn two_htrb_outlives_uses() -> impl for<'b, 'a> Bar<'a, Assoc = impl for<'b> Sized + 'b> {}
26+
| +++
27+
help: consider introducing lifetime `'b` here
28+
|
29+
LL | fn two_htrb_outlives_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Sized + 'b> {}
30+
| ++++
31+
32+
error: higher kinded lifetime bounds on nested opaque types are not supported yet
33+
--> $DIR/nested-rpit-hrtb.rs:25:69
34+
|
35+
LL | fn one_hrtb_outlives() -> impl for<'a> Foo<'a, Assoc = impl Sized + 'a> {}
36+
| ^^
37+
|
38+
note: lifetime declared here
39+
--> $DIR/nested-rpit-hrtb.rs:25:36
40+
|
41+
LL | fn one_hrtb_outlives() -> impl for<'a> Foo<'a, Assoc = impl Sized + 'a> {}
42+
| ^^
43+
44+
error: higher kinded lifetime bounds on nested opaque types are not supported yet
45+
--> $DIR/nested-rpit-hrtb.rs:29:68
46+
|
47+
LL | fn one_hrtb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl Qux<'a>> {}
48+
| ^^
49+
|
50+
note: lifetime declared here
51+
--> $DIR/nested-rpit-hrtb.rs:29:39
52+
|
53+
LL | fn one_hrtb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl Qux<'a>> {}
54+
| ^^
55+
56+
error: higher kinded lifetime bounds on nested opaque types are not supported yet
57+
--> $DIR/nested-rpit-hrtb.rs:32:74
58+
|
59+
LL | fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {}
60+
| ^^
61+
|
62+
note: lifetime declared here
63+
--> $DIR/nested-rpit-hrtb.rs:32:41
64+
|
65+
LL | fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {}
66+
| ^^
67+
68+
error: higher kinded lifetime bounds on nested opaque types are not supported yet
69+
--> $DIR/nested-rpit-hrtb.rs:35:73
70+
|
71+
LL | fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {}
72+
| ^^
73+
|
74+
note: lifetime declared here
75+
--> $DIR/nested-rpit-hrtb.rs:35:44
76+
|
77+
LL | fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {}
78+
| ^^
79+
80+
error: aborting due to 6 previous errors
81+
82+
For more information about this error, try `rustc --explain E0261`.

0 commit comments

Comments
 (0)