]> git.lizzy.rs Git - rust.git/commitdiff
Unconditionally encode hidden types in typeck results
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Tue, 20 Sep 2022 08:56:04 +0000 (08:56 +0000)
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 7 Oct 2022 19:36:32 +0000 (19:36 +0000)
compiler/rustc_hir_analysis/src/check/writeback.rs
compiler/rustc_hir_analysis/src/collect/type_of.rs
compiler/rustc_middle/src/ty/context.rs
src/test/ui/impl-trait/issues/issue-86800.stderr

index 3583769b7cd646c068c8ce477f51ea9848cf517b..f789978ae7e40aea043cdb8572cc17fe899e5ed0 100644 (file)
@@ -536,33 +536,29 @@ fn visit_opaque_types(&mut self) {
         let opaque_types =
             self.fcx.infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
         for (opaque_type_key, decl) in opaque_types {
-            let hidden_type = match decl.origin {
-                hir::OpaqueTyOrigin::FnReturn(_) | hir::OpaqueTyOrigin::AsyncFn(_) => {
-                    let ty = self.resolve(decl.hidden_type.ty, &decl.hidden_type.span);
-                    struct RecursionChecker {
-                        def_id: LocalDefId,
-                    }
-                    impl<'tcx> ty::TypeVisitor<'tcx> for RecursionChecker {
-                        type BreakTy = ();
-                        fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
-                            if let ty::Opaque(def_id, _) = *t.kind() {
-                                if def_id == self.def_id.to_def_id() {
-                                    return ControlFlow::Break(());
-                                }
-                            }
-                            t.super_visit_with(self)
+            let hidden_type = self.resolve(decl.hidden_type.ty, &decl.hidden_type.span);
+
+            struct RecursionChecker {
+                def_id: LocalDefId,
+            }
+            impl<'tcx> ty::TypeVisitor<'tcx> for RecursionChecker {
+                type BreakTy = ();
+                fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
+                    if let ty::Opaque(def_id, _) = *t.kind() {
+                        if def_id == self.def_id.to_def_id() {
+                            return ControlFlow::Break(());
                         }
                     }
-                    if ty
-                        .visit_with(&mut RecursionChecker { def_id: opaque_type_key.def_id })
-                        .is_break()
-                    {
-                        return;
-                    }
-                    Some(ty)
+                    t.super_visit_with(self)
                 }
-                hir::OpaqueTyOrigin::TyAlias => None,
-            };
+            }
+            if hidden_type
+                .visit_with(&mut RecursionChecker { def_id: opaque_type_key.def_id })
+                .is_break()
+            {
+                continue;
+            }
+
             self.typeck_results.concrete_opaque_types.insert(opaque_type_key.def_id, hidden_type);
         }
     }
index f8a62c849107632b68bd7e60a3d0106fcc2e5c71..ad9b124c8ab66855a58bad067d317f9245c37a39 100644 (file)
@@ -788,20 +788,15 @@ fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) {
             // the `concrete_opaque_types` table.
             tcx.ty_error()
         } else {
-            table
-                .concrete_opaque_types
-                .get(&def_id)
-                .copied()
-                .unwrap_or_else(|| {
-                    // We failed to resolve the opaque type or it
-                    // resolves to itself. We interpret this as the
-                    // no values of the hidden type ever being constructed,
-                    // so we can just make the hidden type be `!`.
-                    // For backwards compatibility reasons, we fall back to
-                    // `()` until we the diverging default is changed.
-                    Some(tcx.mk_diverging_default())
-                })
-                .expect("RPIT always have a hidden type from typeck")
+            table.concrete_opaque_types.get(&def_id).copied().unwrap_or_else(|| {
+                // We failed to resolve the opaque type or it
+                // resolves to itself. We interpret this as the
+                // no values of the hidden type ever being constructed,
+                // so we can just make the hidden type be `!`.
+                // For backwards compatibility reasons, we fall back to
+                // `()` until we the diverging default is changed.
+                tcx.mk_diverging_default()
+            })
         }
     })
 }
index 97646003e733969a9ef9ae3a3e362ce72c782a9c..8277d1413587b5bd126db0b7bd9fb7e5daed2cfe 100644 (file)
@@ -539,12 +539,10 @@ pub struct TypeckResults<'tcx> {
     pub tainted_by_errors: Option<ErrorGuaranteed>,
 
     /// All the opaque types that have hidden types set
-    /// by this function. For return-position-impl-trait we also store the
-    /// type here, so that mir-borrowck can figure out hidden types,
+    /// by this function. We also store the
+    /// type here, so that mir-borrowck can use it as a hint for figuring out hidden types,
     /// even if they are only set in dead code (which doesn't show up in MIR).
-    /// For type-alias-impl-trait, this map is only used to prevent query cycles,
-    /// so the hidden types are all `None`.
-    pub concrete_opaque_types: VecMap<LocalDefId, Option<Ty<'tcx>>>,
+    pub concrete_opaque_types: VecMap<LocalDefId, Ty<'tcx>>,
 
     /// Tracks the minimum captures required for a closure;
     /// see `MinCaptureInformationMap` for more details.
index 135d06d44adaefb47258211f666ac715fe0da128..6c4aa35679d5bc9f57abb1df07a1ace6a64f70d7 100644 (file)
@@ -1,3 +1,11 @@
+error: unconstrained opaque type
+  --> $DIR/issue-86800.rs:33:34
+   |
+LL | type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
+   |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = 
+
 
 stack backtrace:
 
@@ -12,8 +20,7 @@ error: internal compiler error: unexpected panic
 
 
 query stack during panic:
-#0 [mir_borrowck] borrow-checking `execute_transaction_fut`
-#1 [type_of] computing type of `TransactionFuture::{opaque#0}`
-#2 [check_mod_item_types] checking item types in top-level module
-#3 [analysis] running analysis passes on this crate
+#0 [type_of] computing type of `TransactionFuture::{opaque#0}`
+#1 [check_mod_item_types] checking item types in top-level module
+#2 [analysis] running analysis passes on this crate
 end of query stack