Add a test demonstrating that RPITITs cant use precise capturing

This commit is contained in:
Michael Goulet 2024-06-20 12:04:59 -04:00
parent 1aaab8b9f8
commit dd557d8c37
2 changed files with 63 additions and 0 deletions

View file

@ -0,0 +1,21 @@
//@ known-bug: unknown
// RPITITs don't have variances in their GATs, so they always relate invariantly
// and act as if they capture all their args.
// To fix this soundly, we need to make sure that all the trait header args
// remain captured, since they affect trait selection.
#![feature(precise_capturing)]
trait Foo<'a> {
fn hello() -> impl PartialEq + use<Self>;
}
fn test<'a, 'b, T: for<'r> Foo<'r>>() {
PartialEq::eq(
&<T as Foo<'a>>::hello(),
&<T as Foo<'b>>::hello(),
);
}
fn main() {}

View file

@ -0,0 +1,42 @@
error: `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list
--> $DIR/rpitit.rs:11:19
|
LL | trait Foo<'a> {
| -- this lifetime parameter is captured
LL | fn hello() -> impl PartialEq + use<Self>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime captured due to being mentioned in the bounds of the `impl Trait`
error: lifetime may not live long enough
--> $DIR/rpitit.rs:15:5
|
LL | fn test<'a, 'b, T: for<'r> Foo<'r>>() {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | / PartialEq::eq(
LL | | &<T as Foo<'a>>::hello(),
LL | | &<T as Foo<'b>>::hello(),
LL | | );
| |_____^ argument requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'a: 'b`
error: lifetime may not live long enough
--> $DIR/rpitit.rs:15:5
|
LL | fn test<'a, 'b, T: for<'r> Foo<'r>>() {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | / PartialEq::eq(
LL | | &<T as Foo<'a>>::hello(),
LL | | &<T as Foo<'b>>::hello(),
LL | | );
| |_____^ argument requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
help: `'a` and `'b` must be the same: replace one with the other
error: aborting due to 3 previous errors