summary refs log tree commit diff
path: root/tests/ui/generics
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/generics')
-rw-r--r--tests/ui/generics/unconstrained-type-params-inherent-impl.rs32
-rw-r--r--tests/ui/generics/unconstrained-type-params-inherent-impl.stderr15
2 files changed, 47 insertions, 0 deletions
diff --git a/tests/ui/generics/unconstrained-type-params-inherent-impl.rs b/tests/ui/generics/unconstrained-type-params-inherent-impl.rs
new file mode 100644
index 00000000000..c971de0d1f2
--- /dev/null
+++ b/tests/ui/generics/unconstrained-type-params-inherent-impl.rs
@@ -0,0 +1,32 @@
+//! Test for unconstrained type parameters in inherent implementations
+
+struct MyType;
+
+struct MyType1<T>(T);
+
+trait Bar {
+    type Out;
+}
+
+impl<T> MyType {
+    //~^ ERROR the type parameter `T` is not constrained
+    // T is completely unused - this should fail
+}
+
+impl<T> MyType1<T> {
+    // OK: T is used in the self type `MyType1<T>`
+}
+
+impl<T, U> MyType1<T> {
+    //~^ ERROR the type parameter `U` is not constrained
+    // T is used in self type, but U is unconstrained - this should fail
+}
+
+impl<T, U> MyType1<T>
+where
+    T: Bar<Out = U>,
+{
+    // OK: T is used in self type, U is constrained through the where clause
+}
+
+fn main() {}
diff --git a/tests/ui/generics/unconstrained-type-params-inherent-impl.stderr b/tests/ui/generics/unconstrained-type-params-inherent-impl.stderr
new file mode 100644
index 00000000000..19b02ad396c
--- /dev/null
+++ b/tests/ui/generics/unconstrained-type-params-inherent-impl.stderr
@@ -0,0 +1,15 @@
+error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
+  --> $DIR/unconstrained-type-params-inherent-impl.rs:11:6
+   |
+LL | impl<T> MyType {
+   |      ^ unconstrained type parameter
+
+error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
+  --> $DIR/unconstrained-type-params-inherent-impl.rs:20:9
+   |
+LL | impl<T, U> MyType1<T> {
+   |         ^ unconstrained type parameter
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0207`.