about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/type-alias-impl-trait/coherence.rs2
-rw-r--r--tests/ui/type-alias-impl-trait/coherence.stderr13
-rw-r--r--tests/ui/type-alias-impl-trait/coherence_generalization.rs4
-rw-r--r--tests/ui/type-alias-impl-trait/coherence_generalization.stderr9
-rw-r--r--tests/ui/type-alias-impl-trait/unconstrained-impl-param.rs25
-rw-r--r--tests/ui/type-alias-impl-trait/unconstrained-impl-param.stderr9
6 files changed, 50 insertions, 12 deletions
diff --git a/tests/ui/type-alias-impl-trait/coherence.rs b/tests/ui/type-alias-impl-trait/coherence.rs
index 077a31494a9..1c0f83d6c12 100644
--- a/tests/ui/type-alias-impl-trait/coherence.rs
+++ b/tests/ui/type-alias-impl-trait/coherence.rs
@@ -12,6 +12,6 @@ fn use_alias<T>(val: T) -> AliasOfForeignType<T> {
 }
 
 impl<T> foreign_crate::ForeignTrait for AliasOfForeignType<T> {}
-//~^ ERROR only traits defined in the current crate can be implemented for arbitrary types
+//~^ ERROR the type parameter `T` is not constrained by the impl trait, self type, or predicates
 
 fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/coherence.stderr b/tests/ui/type-alias-impl-trait/coherence.stderr
index c923eb08ab3..6ede0fa14ba 100644
--- a/tests/ui/type-alias-impl-trait/coherence.stderr
+++ b/tests/ui/type-alias-impl-trait/coherence.stderr
@@ -1,14 +1,9 @@
-error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
-  --> $DIR/coherence.rs:14:1
+error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
+  --> $DIR/coherence.rs:14:6
    |
 LL | impl<T> foreign_crate::ForeignTrait for AliasOfForeignType<T> {}
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------
-   | |                                       |
-   | |                                       `AliasOfForeignType<T>` is not defined in the current crate
-   | impl doesn't use only types from inside the current crate
-   |
-   = note: define and implement a trait or new type instead
+   |      ^ unconstrained type parameter
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0117`.
+For more information about this error, try `rustc --explain E0207`.
diff --git a/tests/ui/type-alias-impl-trait/coherence_generalization.rs b/tests/ui/type-alias-impl-trait/coherence_generalization.rs
index 679b2b0f188..0e9e0e23270 100644
--- a/tests/ui/type-alias-impl-trait/coherence_generalization.rs
+++ b/tests/ui/type-alias-impl-trait/coherence_generalization.rs
@@ -1,7 +1,6 @@
-// check-pass
-
 // FIXME(type_alias_impl_trait): What does this test? This needs a comment
 // explaining what we're worried about here.
+
 #![feature(type_alias_impl_trait)]
 trait Trait {}
 type Opaque<T> = impl Sized;
@@ -11,5 +10,6 @@ fn foo<T>() -> Opaque<T> {
 
 impl<T, V> Trait for (T, V, V, u32) {}
 impl<U, V> Trait for (Opaque<U>, V, i32, V) {}
+//~^ ERROR the type parameter `U` is not constrained by the impl trait, self type, or predicates
 
 fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/coherence_generalization.stderr b/tests/ui/type-alias-impl-trait/coherence_generalization.stderr
new file mode 100644
index 00000000000..d5148fbdacf
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/coherence_generalization.stderr
@@ -0,0 +1,9 @@
+error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
+  --> $DIR/coherence_generalization.rs:12:6
+   |
+LL | impl<U, V> Trait for (Opaque<U>, V, i32, V) {}
+   |      ^ unconstrained type parameter
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0207`.
diff --git a/tests/ui/type-alias-impl-trait/unconstrained-impl-param.rs b/tests/ui/type-alias-impl-trait/unconstrained-impl-param.rs
new file mode 100644
index 00000000000..288e7d34b48
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/unconstrained-impl-param.rs
@@ -0,0 +1,25 @@
+#![feature(type_alias_impl_trait)]
+
+use std::fmt::Display;
+
+type Opaque<'a> = impl Sized + 'static;
+fn define<'a>() -> Opaque<'a> {}
+
+trait Trait {
+    type Assoc: Display;
+}
+impl<'a> Trait for Opaque<'a> {
+    //~^ ERROR the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
+    type Assoc = &'a str;
+}
+
+// ======= Exploit =======
+
+fn extend<T: Trait + 'static>(s: T::Assoc) -> Box<dyn Display> {
+    Box::new(s)
+}
+
+fn main() {
+    let val = extend::<Opaque<'_>>(&String::from("blah blah blah"));
+    println!("{}", val);
+}
diff --git a/tests/ui/type-alias-impl-trait/unconstrained-impl-param.stderr b/tests/ui/type-alias-impl-trait/unconstrained-impl-param.stderr
new file mode 100644
index 00000000000..6fe265c5e20
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/unconstrained-impl-param.stderr
@@ -0,0 +1,9 @@
+error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
+  --> $DIR/unconstrained-impl-param.rs:11:6
+   |
+LL | impl<'a> Trait for Opaque<'a> {
+   |      ^^ unconstrained lifetime parameter
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0207`.