Skip to content

Commit

Permalink
Add a test demonstrating that RPITITs cant use precise capturing
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jun 20, 2024
1 parent 1aaab8b commit dd557d8
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/ui/impl-trait/precise-capturing/rpitit.rs
Original file line number Diff line number Diff line change
@@ -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() {}
42 changes: 42 additions & 0 deletions tests/ui/impl-trait/precise-capturing/rpitit.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit dd557d8

Please sign in to comment.