Skip to content

Commit 7d0f04a

Browse files
committed
Add a test with both passing and erroneous cases.
1 parent c98eae6 commit 7d0f04a

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed

Diff for: src/test/ui/impl-trait/nested-rpit-hrtb.rs

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
//~| ERROR lifetime name `'b` shadows a lifetime name that is already in scope [E0496]
57+
58+
// This should pass.
59+
fn two_htrb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Qux<'b>> {}
60+
61+
// `'b` is not in scope for the outlives bound.
62+
fn two_htrb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Sized + 'b> {}
63+
//~^ ERROR use of undeclared lifetime name `'b` [E0261]
64+
//~| ERROR lifetime name `'b` shadows a lifetime name that is already in scope [E0496]
65+
66+
fn main() {}

Diff for: src/test/ui/impl-trait/nested-rpit-hrtb.stderr

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
error: higher kinded lifetime bounds on nested opaque types are not supported yet
2+
--> $DIR/nested-rpit-hrtb.rs:25:69
3+
|
4+
LL | fn one_hrtb_outlives() -> impl for<'a> Foo<'a, Assoc = impl Sized + 'a> {}
5+
| ^^
6+
|
7+
note: lifetime declared here
8+
--> $DIR/nested-rpit-hrtb.rs:25:36
9+
|
10+
LL | fn one_hrtb_outlives() -> impl for<'a> Foo<'a, Assoc = impl Sized + 'a> {}
11+
| ^^
12+
13+
error: higher kinded lifetime bounds on nested opaque types are not supported yet
14+
--> $DIR/nested-rpit-hrtb.rs:29:68
15+
|
16+
LL | fn one_hrtb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl Qux<'a>> {}
17+
| ^^
18+
|
19+
note: lifetime declared here
20+
--> $DIR/nested-rpit-hrtb.rs:29:39
21+
|
22+
LL | fn one_hrtb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl Qux<'a>> {}
23+
| ^^
24+
25+
error: higher kinded lifetime bounds on nested opaque types are not supported yet
26+
--> $DIR/nested-rpit-hrtb.rs:32:74
27+
|
28+
LL | fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {}
29+
| ^^
30+
|
31+
note: lifetime declared here
32+
--> $DIR/nested-rpit-hrtb.rs:32:41
33+
|
34+
LL | fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {}
35+
| ^^
36+
37+
error: higher kinded lifetime bounds on nested opaque types are not supported yet
38+
--> $DIR/nested-rpit-hrtb.rs:35:73
39+
|
40+
LL | fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {}
41+
| ^^
42+
|
43+
note: lifetime declared here
44+
--> $DIR/nested-rpit-hrtb.rs:35:44
45+
|
46+
LL | fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {}
47+
| ^^
48+
49+
error[E0261]: use of undeclared lifetime name `'b`
50+
--> $DIR/nested-rpit-hrtb.rs:54:77
51+
|
52+
LL | fn two_htrb_outlives() -> impl for<'a> Foo<'a, Assoc = impl for<'b> Sized + 'b> {}
53+
| - help: consider introducing lifetime `'b` here: `<'b>` ^^ undeclared lifetime
54+
55+
error[E0496]: lifetime name `'b` shadows a lifetime name that is already in scope
56+
--> $DIR/nested-rpit-hrtb.rs:54:65
57+
|
58+
LL | fn two_htrb_outlives() -> impl for<'a> Foo<'a, Assoc = impl for<'b> Sized + 'b> {}
59+
| ^^ -- first declared here
60+
| |
61+
| lifetime `'b` already in scope
62+
63+
error[E0261]: use of undeclared lifetime name `'b`
64+
--> $DIR/nested-rpit-hrtb.rs:62:82
65+
|
66+
LL | fn two_htrb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Sized + 'b> {}
67+
| - help: consider introducing lifetime `'b` here: `<'b>` ^^ undeclared lifetime
68+
69+
error[E0496]: lifetime name `'b` shadows a lifetime name that is already in scope
70+
--> $DIR/nested-rpit-hrtb.rs:62:70
71+
|
72+
LL | fn two_htrb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Sized + 'b> {}
73+
| ^^ -- first declared here
74+
| |
75+
| lifetime `'b` already in scope
76+
77+
error: aborting due to 8 previous errors
78+
79+
Some errors have detailed explanations: E0261, E0496.
80+
For more information about an error, try `rustc --explain E0261`.

0 commit comments

Comments
 (0)