about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_middle/src/ty/error.rs15
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-89686.rs24
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-89686.stderr34
3 files changed, 68 insertions, 5 deletions
diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs
index 08b4d3aecda..bac681bd96f 100644
--- a/compiler/rustc_middle/src/ty/error.rs
+++ b/compiler/rustc_middle/src/ty/error.rs
@@ -769,11 +769,16 @@ fn foo(&self) -> Self::T { String::new() }
     ) -> bool {
         let assoc = self.associated_item(proj_ty.item_def_id);
         if let ty::Opaque(def_id, _) = *proj_ty.self_ty().kind() {
-            let opaque_local_def_id = def_id.expect_local();
-            let opaque_hir_id = self.hir().local_def_id_to_hir_id(opaque_local_def_id);
-            let opaque_hir_ty = match &self.hir().expect_item(opaque_hir_id).kind {
-                hir::ItemKind::OpaqueTy(opaque_hir_ty) => opaque_hir_ty,
-                _ => bug!("The HirId comes from a `ty::Opaque`"),
+            let opaque_local_def_id = def_id.as_local();
+            let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id {
+                let hir = self.hir();
+                let opaque_hir_id = hir.local_def_id_to_hir_id(opaque_local_def_id);
+                match &hir.expect_item(opaque_hir_id).kind {
+                    hir::ItemKind::OpaqueTy(opaque_hir_ty) => opaque_hir_ty,
+                    _ => bug!("The HirId comes from a `ty::Opaque`"),
+                }
+            } else {
+                return false;
             };
 
             let (trait_ref, assoc_substs) = proj_ty.trait_ref_and_own_substs(self);
diff --git a/src/test/ui/type-alias-impl-trait/issue-89686.rs b/src/test/ui/type-alias-impl-trait/issue-89686.rs
new file mode 100644
index 00000000000..2b6ce49e7e2
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/issue-89686.rs
@@ -0,0 +1,24 @@
+// edition:2018
+
+#![feature(type_alias_impl_trait)]
+
+use std::future::Future;
+
+type G<'a, T> = impl Future<Output = ()>;
+//~^ ERROR: type mismatch resolving `<impl Future as Future>::Output == ()`
+//~| ERROR: the trait bound `T: Trait` is not satisfied
+
+trait Trait {
+    type F: Future<Output = ()>;
+
+    fn f(&self) -> Self::F;
+
+    fn g<'a>(&'a self) -> G<'a, Self>
+    where
+        Self: Sized,
+    {
+        async move { self.f().await }
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/type-alias-impl-trait/issue-89686.stderr b/src/test/ui/type-alias-impl-trait/issue-89686.stderr
new file mode 100644
index 00000000000..accc84d30a7
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/issue-89686.stderr
@@ -0,0 +1,34 @@
+error[E0271]: type mismatch resolving `<impl Future as Future>::Output == ()`
+  --> $DIR/issue-89686.rs:7:17
+   |
+LL | type G<'a, T> = impl Future<Output = ()>;
+   |                 ^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type
+...
+LL |         async move { self.f().await }
+   |                    ------------------ the found `async` block
+   |
+  ::: $SRC_DIR/core/src/future/mod.rs:LL:COL
+   |
+LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
+   |                                           ------------------------------- the found opaque type
+   |
+   = note:    expected unit type `()`
+           found associated type `<impl Future as Future>::Output`
+   = help: consider constraining the associated type `<impl Future as Future>::Output` to `()`
+   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
+
+error[E0277]: the trait bound `T: Trait` is not satisfied
+  --> $DIR/issue-89686.rs:7:17
+   |
+LL | type G<'a, T> = impl Future<Output = ()>;
+   |                 ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T`
+   |
+help: consider restricting type parameter `T`
+   |
+LL | type G<'a, T: Trait> = impl Future<Output = ()>;
+   |             +++++++
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0271, E0277.
+For more information about an error, try `rustc --explain E0271`.