Skip to content

Commit 40b3cb0

Browse files
committed
Don't reinvoke trait_header query twice
1 parent 55bbb05 commit 40b3cb0

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ use rustc_trait_selection::traits::ObligationCtxt;
2525
use rustc_trait_selection::traits::{self, ObligationCause};
2626
use std::collections::BTreeMap;
2727

28-
pub fn check_trait(
29-
tcx: TyCtxt<'_>,
28+
pub fn check_trait<'tcx>(
29+
tcx: TyCtxt<'tcx>,
3030
trait_def_id: DefId,
3131
impl_def_id: LocalDefId,
32+
impl_header: ty::ImplTraitHeader<'tcx>,
3233
) -> Result<(), ErrorGuaranteed> {
3334
let lang_items = tcx.lang_items();
3435
let checker = Checker { tcx, trait_def_id, impl_def_id };
@@ -40,10 +41,9 @@ pub fn check_trait(
4041
res = res.and(
4142
checker.check(lang_items.coerce_unsized_trait(), visit_implementation_of_coerce_unsized),
4243
);
43-
res.and(
44-
checker
45-
.check(lang_items.dispatch_from_dyn_trait(), visit_implementation_of_dispatch_from_dyn),
46-
)
44+
res.and(checker.check(lang_items.dispatch_from_dyn_trait(), |tcx, id| {
45+
visit_implementation_of_dispatch_from_dyn(tcx, id, impl_header.trait_ref)
46+
}))
4747
}
4848

4949
struct Checker<'tcx> {
@@ -151,20 +151,20 @@ fn visit_implementation_of_coerce_unsized(
151151
tcx.at(span).ensure().coerce_unsized_info(impl_did)
152152
}
153153

154-
fn visit_implementation_of_dispatch_from_dyn(
155-
tcx: TyCtxt<'_>,
154+
fn visit_implementation_of_dispatch_from_dyn<'tcx>(
155+
tcx: TyCtxt<'tcx>,
156156
impl_did: LocalDefId,
157+
trait_ref: ty::TraitRef<'tcx>,
157158
) -> Result<(), ErrorGuaranteed> {
158159
debug!("visit_implementation_of_dispatch_from_dyn: impl_did={:?}", impl_did);
159160

160161
let span = tcx.def_span(impl_did);
161162

162163
let dispatch_from_dyn_trait = tcx.require_lang_item(LangItem::DispatchFromDyn, Some(span));
163164

164-
let source = tcx.type_of(impl_did).instantiate_identity();
165+
let source = trait_ref.self_ty();
165166
assert!(!source.has_escaping_bound_vars());
166167
let target = {
167-
let trait_ref = tcx.impl_trait_ref(impl_did).unwrap().instantiate_identity();
168168
assert_eq!(trait_ref.def_id, dispatch_from_dyn_trait);
169169

170170
trait_ref.args.type_at(1)

compiler/rustc_hir_analysis/src/coherence/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Result<(), ErrorGuaranteed>
142142

143143
res = res.and(unsafety::check_item(tcx, impl_def_id, trait_header, trait_def));
144144
res = res.and(tcx.ensure().orphan_check_impl(impl_def_id));
145-
res = res.and(builtin::check_trait(tcx, def_id, impl_def_id));
145+
res = res.and(builtin::check_trait(tcx, def_id, impl_def_id, trait_header));
146146
}
147147

148148
res

0 commit comments

Comments
 (0)