about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-02-13 09:38:13 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-02-13 09:38:13 +0000
commit40b3cb0eb15528e6a5469a3d783908f4bd1cf731 (patch)
treefd4245669251aba69ddfbfe9b1edf8b9148b80c9
parent55bbb054c937ea53de4e8bdc01b8c5eab82b9635 (diff)
downloadrust-40b3cb0eb15528e6a5469a3d783908f4bd1cf731.tar.gz
rust-40b3cb0eb15528e6a5469a3d783908f4bd1cf731.zip
Don't reinvoke `trait_header` query twice
-rw-r--r--compiler/rustc_hir_analysis/src/coherence/builtin.rs20
-rw-r--r--compiler/rustc_hir_analysis/src/coherence/mod.rs2
2 files changed, 11 insertions, 11 deletions
diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs
index 370c6c607d7..a2efa0c99a2 100644
--- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs
+++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs
@@ -25,10 +25,11 @@ use rustc_trait_selection::traits::ObligationCtxt;
 use rustc_trait_selection::traits::{self, ObligationCause};
 use std::collections::BTreeMap;
 
-pub fn check_trait(
-    tcx: TyCtxt<'_>,
+pub fn check_trait<'tcx>(
+    tcx: TyCtxt<'tcx>,
     trait_def_id: DefId,
     impl_def_id: LocalDefId,
+    impl_header: ty::ImplTraitHeader<'tcx>,
 ) -> Result<(), ErrorGuaranteed> {
     let lang_items = tcx.lang_items();
     let checker = Checker { tcx, trait_def_id, impl_def_id };
@@ -40,10 +41,9 @@ pub fn check_trait(
     res = res.and(
         checker.check(lang_items.coerce_unsized_trait(), visit_implementation_of_coerce_unsized),
     );
-    res.and(
-        checker
-            .check(lang_items.dispatch_from_dyn_trait(), visit_implementation_of_dispatch_from_dyn),
-    )
+    res.and(checker.check(lang_items.dispatch_from_dyn_trait(), |tcx, id| {
+        visit_implementation_of_dispatch_from_dyn(tcx, id, impl_header.trait_ref)
+    }))
 }
 
 struct Checker<'tcx> {
@@ -151,9 +151,10 @@ fn visit_implementation_of_coerce_unsized(
     tcx.at(span).ensure().coerce_unsized_info(impl_did)
 }
 
-fn visit_implementation_of_dispatch_from_dyn(
-    tcx: TyCtxt<'_>,
+fn visit_implementation_of_dispatch_from_dyn<'tcx>(
+    tcx: TyCtxt<'tcx>,
     impl_did: LocalDefId,
+    trait_ref: ty::TraitRef<'tcx>,
 ) -> Result<(), ErrorGuaranteed> {
     debug!("visit_implementation_of_dispatch_from_dyn: impl_did={:?}", impl_did);
 
@@ -161,10 +162,9 @@ fn visit_implementation_of_dispatch_from_dyn(
 
     let dispatch_from_dyn_trait = tcx.require_lang_item(LangItem::DispatchFromDyn, Some(span));
 
-    let source = tcx.type_of(impl_did).instantiate_identity();
+    let source = trait_ref.self_ty();
     assert!(!source.has_escaping_bound_vars());
     let target = {
-        let trait_ref = tcx.impl_trait_ref(impl_did).unwrap().instantiate_identity();
         assert_eq!(trait_ref.def_id, dispatch_from_dyn_trait);
 
         trait_ref.args.type_at(1)
diff --git a/compiler/rustc_hir_analysis/src/coherence/mod.rs b/compiler/rustc_hir_analysis/src/coherence/mod.rs
index 793458c4d8d..d6281fa08f7 100644
--- a/compiler/rustc_hir_analysis/src/coherence/mod.rs
+++ b/compiler/rustc_hir_analysis/src/coherence/mod.rs
@@ -142,7 +142,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Result<(), ErrorGuaranteed>
 
         res = res.and(unsafety::check_item(tcx, impl_def_id, trait_header, trait_def));
         res = res.and(tcx.ensure().orphan_check_impl(impl_def_id));
-        res = res.and(builtin::check_trait(tcx, def_id, impl_def_id));
+        res = res.and(builtin::check_trait(tcx, def_id, impl_def_id, trait_header));
     }
 
     res