about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.rs24
-rw-r--r--tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.stderr12
-rw-r--r--tests/ui/traits/object/pretty.rs4
-rw-r--r--tests/ui/traits/object/pretty.stderr13
4 files changed, 39 insertions, 14 deletions
diff --git a/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.rs b/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.rs
new file mode 100644
index 00000000000..b174776c596
--- /dev/null
+++ b/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.rs
@@ -0,0 +1,24 @@
+// Make sure that when elaborating the principal of a dyn trait for projection predicates
+//  we don't end up in a situation where we have an unconstrained late-bound lifetime in
+// the output of a projection.
+
+// Fix for <https://github.com/rust-lang/rust/issues/130347>.
+
+trait A<T>: B<T = T> {}
+
+trait B {
+    type T;
+}
+
+struct Erase<T: ?Sized + B>(T::T);
+
+fn main() {
+    let x = {
+        let x = String::from("hello");
+
+        Erase::<dyn for<'a> A<&'a _>>(x.as_str())
+        //~^ ERROR binding for associated type `T` references lifetime `'a`, which does not appear in the trait input types
+    };
+
+    dbg!(x.0);
+}
diff --git a/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.stderr b/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.stderr
new file mode 100644
index 00000000000..067eaf5e7f3
--- /dev/null
+++ b/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.stderr
@@ -0,0 +1,12 @@
+error[E0582]: binding for associated type `T` references lifetime `'a`, which does not appear in the trait input types
+  --> $DIR/elaborated-predicates-unconstrained-late-bound.rs:19:21
+   |
+LL | trait A<T>: B<T = T> {}
+   |               ----- due to this supertrait
+...
+LL |         Erase::<dyn for<'a> A<&'a _>>(x.as_str())
+   |                     ^^^^^^^^^^^^^^^^
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0582`.
diff --git a/tests/ui/traits/object/pretty.rs b/tests/ui/traits/object/pretty.rs
index 6660ff040f7..603d7af5260 100644
--- a/tests/ui/traits/object/pretty.rs
+++ b/tests/ui/traits/object/pretty.rs
@@ -13,7 +13,7 @@ trait SuperGeneric<'a> {
 }
 trait AnyGeneric<'a>: SuperGeneric<'a> {}
 trait FixedGeneric1<'a>: SuperGeneric<'a, Assoc2 = &'a u8> {}
-trait FixedGeneric2<'a>: Super<Assoc = &'a u8> {}
+// trait FixedGeneric2<'a>: Super<Assoc = &'a u8> {} // Unsound!
 trait FixedHrtb: for<'a> SuperGeneric<'a, Assoc2 = &'a u8> {}
 trait AnyDifferentBinders: for<'a> SuperGeneric<'a, Assoc2 = &'a u8> + Super {}
 trait FixedDifferentBinders: for<'a> SuperGeneric<'a, Assoc2 = &'a u8> + Super<Assoc = u8> {}
@@ -32,7 +32,7 @@ fn dyn_fixed_static(x: &dyn FixedStatic) { x } //~ERROR mismatched types
 fn dyn_super_generic(x: &dyn for<'a> SuperGeneric<'a, Assoc2 = &'a u8>) { x } //~ERROR mismatched types
 fn dyn_any_generic(x: &dyn for<'a> AnyGeneric<'a, Assoc2 = &'a u8>) { x } //~ERROR mismatched types
 fn dyn_fixed_generic1(x: &dyn for<'a> FixedGeneric1<'a>) { x } //~ERROR mismatched types
-fn dyn_fixed_generic2(x: &dyn for<'a> FixedGeneric2<'a>) { x } //~ERROR mismatched types
+// fn dyn_fixed_generic2(x: &dyn for<'a> FixedGeneric2<'a>) { x } // Unsound!
 fn dyn_fixed_generic_multi(x: &dyn for<'a> FixedGeneric1<'a, Assoc2 = &u8>) { x } //~ERROR mismatched types
 fn dyn_fixed_hrtb(x: &dyn FixedHrtb) { x } //~ERROR mismatched types
 fn dyn_any_different_binders(x: &dyn AnyDifferentBinders<Assoc = u8>) { x } //~ERROR mismatched types
diff --git a/tests/ui/traits/object/pretty.stderr b/tests/ui/traits/object/pretty.stderr
index ca56bdbb67a..af941e69c5f 100644
--- a/tests/ui/traits/object/pretty.stderr
+++ b/tests/ui/traits/object/pretty.stderr
@@ -107,17 +107,6 @@ LL | fn dyn_fixed_generic1(x: &dyn for<'a> FixedGeneric1<'a>) { x }
               found reference `&dyn for<'a> FixedGeneric1<'a>`
 
 error[E0308]: mismatched types
-  --> $DIR/pretty.rs:35:60
-   |
-LL | fn dyn_fixed_generic2(x: &dyn for<'a> FixedGeneric2<'a>) { x }
-   |                                                         -  ^ expected `()`, found `&dyn FixedGeneric2<'a>`
-   |                                                         |
-   |                                                         help: try adding a return type: `-> &dyn for<'a> FixedGeneric2<'a>`
-   |
-   = note: expected unit type `()`
-              found reference `&dyn for<'a> FixedGeneric2<'a>`
-
-error[E0308]: mismatched types
   --> $DIR/pretty.rs:36:79
    |
 LL | fn dyn_fixed_generic_multi(x: &dyn for<'a> FixedGeneric1<'a, Assoc2 = &u8>) { x }
@@ -172,6 +161,6 @@ LL | fn dyn_has_gat(x: &dyn HasGat<u8, Assoc<bool> = ()>) { x }
    = note: expected unit type `()`
               found reference `&dyn HasGat<u8, Assoc<bool> = ()>`
 
-error: aborting due to 15 previous errors; 1 warning emitted
+error: aborting due to 14 previous errors; 1 warning emitted
 
 For more information about this error, try `rustc --explain E0308`.