Skip to content

Commit de4d615

Browse files
committed
Auto merge of #120834 - oli-obk:only_local_coherence, r=lcnr
A trait's local impls are trivially coherent if there are no impls. This avoids creating a dependency edge on the hir or the specialization graph This may resolve part of the performance issue of #120558
2 parents 084ce5b + e2349ea commit de4d615

File tree

1 file changed

+3
-1
lines changed
  • compiler/rustc_hir_analysis/src/coherence

1 file changed

+3
-1
lines changed

compiler/rustc_hir_analysis/src/coherence/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,13 @@ pub fn provide(providers: &mut Providers) {
124124
}
125125

126126
fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Result<(), ErrorGuaranteed> {
127+
// If there are no impls for the trait, then "all impls" are trivially coherent and we won't check anything
128+
// anyway. Thus we bail out even before the specialization graph, avoiding the dep_graph edge.
129+
let Some(impls) = tcx.all_local_trait_impls(()).get(&def_id) else { return Ok(()) };
127130
// Trigger building the specialization graph for the trait. This will detect and report any
128131
// overlap errors.
129132
let mut res = tcx.ensure().specialization_graph_of(def_id);
130133

131-
let impls = tcx.hir().trait_impls(def_id);
132134
for &impl_def_id in impls {
133135
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().instantiate_identity();
134136

0 commit comments

Comments
 (0)