about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tests/ui/impl-trait/precise-capturing/rpitit.rs21
-rw-r--r--tests/ui/impl-trait/precise-capturing/rpitit.stderr42
2 files changed, 63 insertions, 0 deletions
diff --git a/tests/ui/impl-trait/precise-capturing/rpitit.rs b/tests/ui/impl-trait/precise-capturing/rpitit.rs
new file mode 100644
index 00000000000..4eb053573e1
--- /dev/null
+++ b/tests/ui/impl-trait/precise-capturing/rpitit.rs
@@ -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() {}
diff --git a/tests/ui/impl-trait/precise-capturing/rpitit.stderr b/tests/ui/impl-trait/precise-capturing/rpitit.stderr
new file mode 100644
index 00000000000..202eeb39385
--- /dev/null
+++ b/tests/ui/impl-trait/precise-capturing/rpitit.stderr
@@ -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
+