about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/lazy-type-alias/constrained-params.rs27
-rw-r--r--tests/ui/lazy-type-alias/unconstrained-param-due-to-overflow.rs8
-rw-r--r--tests/ui/lazy-type-alias/unconstrained-param-due-to-overflow.stderr9
-rw-r--r--tests/ui/lazy-type-alias/unconstrained-params.rs12
-rw-r--r--tests/ui/lazy-type-alias/unconstrained-params.stderr9
5 files changed, 65 insertions, 0 deletions
diff --git a/tests/ui/lazy-type-alias/constrained-params.rs b/tests/ui/lazy-type-alias/constrained-params.rs
new file mode 100644
index 00000000000..59693dd5461
--- /dev/null
+++ b/tests/ui/lazy-type-alias/constrained-params.rs
@@ -0,0 +1,27 @@
+//@ check-pass
+
+#![feature(lazy_type_alias)]
+#![allow(incomplete_features)]
+
+type Injective<T> = Local<T>;
+struct Local<T>(T);
+
+impl<T> Injective<T> {
+    fn take(_: T) {}
+}
+
+trait Trait {
+    type Out;
+    fn produce() -> Self::Out;
+}
+
+impl<T: Default> Trait for Injective<T> {
+    type Out = T;
+    fn produce() -> Self::Out { T::default() }
+}
+
+fn main() {
+    Injective::take(0);
+    let _: String = Injective::produce();
+    let _: bool = Local::produce();
+}
diff --git a/tests/ui/lazy-type-alias/unconstrained-param-due-to-overflow.rs b/tests/ui/lazy-type-alias/unconstrained-param-due-to-overflow.rs
new file mode 100644
index 00000000000..eceefa719ec
--- /dev/null
+++ b/tests/ui/lazy-type-alias/unconstrained-param-due-to-overflow.rs
@@ -0,0 +1,8 @@
+#![feature(lazy_type_alias)]
+#![allow(incomplete_features)]
+
+impl<T> Loop<T> {} //~ ERROR the type parameter `T` is not constrained
+
+type Loop<T> = Loop<T>;
+
+fn main() {}
diff --git a/tests/ui/lazy-type-alias/unconstrained-param-due-to-overflow.stderr b/tests/ui/lazy-type-alias/unconstrained-param-due-to-overflow.stderr
new file mode 100644
index 00000000000..9af6f5dda0b
--- /dev/null
+++ b/tests/ui/lazy-type-alias/unconstrained-param-due-to-overflow.stderr
@@ -0,0 +1,9 @@
+error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
+  --> $DIR/unconstrained-param-due-to-overflow.rs:4:6
+   |
+LL | impl<T> Loop<T> {}
+   |      ^ unconstrained type parameter
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0207`.
diff --git a/tests/ui/lazy-type-alias/unconstrained-params.rs b/tests/ui/lazy-type-alias/unconstrained-params.rs
new file mode 100644
index 00000000000..d58938b3070
--- /dev/null
+++ b/tests/ui/lazy-type-alias/unconstrained-params.rs
@@ -0,0 +1,12 @@
+#![feature(lazy_type_alias)]
+#![allow(incomplete_features)]
+
+impl<T> NotInjective<T> {} //~ ERROR the type parameter `T` is not constrained
+
+type NotInjective<T: ?Sized> = Local<<T as Discard>::Out>;
+struct Local<T>(T);
+
+trait Discard { type Out; }
+impl<T: ?Sized> Discard for T { type Out = (); }
+
+fn main() {}
diff --git a/tests/ui/lazy-type-alias/unconstrained-params.stderr b/tests/ui/lazy-type-alias/unconstrained-params.stderr
new file mode 100644
index 00000000000..3c52a06c319
--- /dev/null
+++ b/tests/ui/lazy-type-alias/unconstrained-params.stderr
@@ -0,0 +1,9 @@
+error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
+  --> $DIR/unconstrained-params.rs:4:6
+   |
+LL | impl<T> NotInjective<T> {}
+   |      ^ unconstrained type parameter
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0207`.