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/associated-type-impl-trait-lifetime.rs7
-rw-r--r--tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.rs16
-rw-r--r--tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.stderr22
3 files changed, 41 insertions, 4 deletions
diff --git a/tests/ui/type-alias-impl-trait/associated-type-impl-trait-lifetime.rs b/tests/ui/type-alias-impl-trait/associated-type-impl-trait-lifetime.rs
index 551815d021a..21c1d8bcc98 100644
--- a/tests/ui/type-alias-impl-trait/associated-type-impl-trait-lifetime.rs
+++ b/tests/ui/type-alias-impl-trait/associated-type-impl-trait-lifetime.rs
@@ -5,15 +5,14 @@
 trait Trait {
     type Opaque1;
     type Opaque2;
-    fn constrain(self);
+    fn constrain(self) -> (Self::Opaque1, Self::Opaque2);
 }
 
 impl<'a> Trait for &'a () {
     type Opaque1 = impl Sized;
     type Opaque2 = impl Sized + 'a;
-    fn constrain(self) {
-        let _: Self::Opaque1 = ();
-        let _: Self::Opaque2 = self;
+    fn constrain(self) -> (Self::Opaque1, Self::Opaque2) {
+        ((), self)
     }
 }
 
diff --git a/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.rs b/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.rs
new file mode 100644
index 00000000000..93c52126d69
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.rs
@@ -0,0 +1,16 @@
+#![feature(impl_trait_in_assoc_type)]
+
+trait Foo {
+    type Foo;
+    fn bar();
+}
+
+impl Foo for () {
+    type Foo = impl std::fmt::Debug;
+    fn bar() {
+        let x: Self::Foo = ();
+        //~^ ERROR: mismatched types
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.stderr b/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.stderr
new file mode 100644
index 00000000000..2beed73cb85
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.stderr
@@ -0,0 +1,22 @@
+error[E0308]: mismatched types
+  --> $DIR/invalid_impl_trait_in_assoc_ty.rs:11:28
+   |
+LL |     type Foo = impl std::fmt::Debug;
+   |                -------------------- the expected opaque type
+LL |     fn bar() {
+LL |         let x: Self::Foo = ();
+   |                ---------   ^^ expected opaque type, found `()`
+   |                |
+   |                expected due to this
+   |
+   = note: expected opaque type `<() as Foo>::Foo`
+                found unit type `()`
+note: this item must have the opaque type in its signature in order to be able to register hidden types
+  --> $DIR/invalid_impl_trait_in_assoc_ty.rs:10:5
+   |
+LL |     fn bar() {
+   |     ^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.