Skip to content

Commit dd557d8

Browse files
Add a test demonstrating that RPITITs cant use precise capturing
1 parent 1aaab8b commit dd557d8

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ known-bug: unknown
2+
3+
// RPITITs don't have variances in their GATs, so they always relate invariantly
4+
// and act as if they capture all their args.
5+
// To fix this soundly, we need to make sure that all the trait header args
6+
// remain captured, since they affect trait selection.
7+
8+
#![feature(precise_capturing)]
9+
10+
trait Foo<'a> {
11+
fn hello() -> impl PartialEq + use<Self>;
12+
}
13+
14+
fn test<'a, 'b, T: for<'r> Foo<'r>>() {
15+
PartialEq::eq(
16+
&<T as Foo<'a>>::hello(),
17+
&<T as Foo<'b>>::hello(),
18+
);
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
error: `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list
2+
--> $DIR/rpitit.rs:11:19
3+
|
4+
LL | trait Foo<'a> {
5+
| -- this lifetime parameter is captured
6+
LL | fn hello() -> impl PartialEq + use<Self>;
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime captured due to being mentioned in the bounds of the `impl Trait`
8+
9+
error: lifetime may not live long enough
10+
--> $DIR/rpitit.rs:15:5
11+
|
12+
LL | fn test<'a, 'b, T: for<'r> Foo<'r>>() {
13+
| -- -- lifetime `'b` defined here
14+
| |
15+
| lifetime `'a` defined here
16+
LL | / PartialEq::eq(
17+
LL | | &<T as Foo<'a>>::hello(),
18+
LL | | &<T as Foo<'b>>::hello(),
19+
LL | | );
20+
| |_____^ argument requires that `'a` must outlive `'b`
21+
|
22+
= help: consider adding the following bound: `'a: 'b`
23+
24+
error: lifetime may not live long enough
25+
--> $DIR/rpitit.rs:15:5
26+
|
27+
LL | fn test<'a, 'b, T: for<'r> Foo<'r>>() {
28+
| -- -- lifetime `'b` defined here
29+
| |
30+
| lifetime `'a` defined here
31+
LL | / PartialEq::eq(
32+
LL | | &<T as Foo<'a>>::hello(),
33+
LL | | &<T as Foo<'b>>::hello(),
34+
LL | | );
35+
| |_____^ argument requires that `'b` must outlive `'a`
36+
|
37+
= help: consider adding the following bound: `'b: 'a`
38+
39+
help: `'a` and `'b` must be the same: replace one with the other
40+
41+
error: aborting due to 3 previous errors
42+

0 commit comments

Comments
 (0)