From 0727f9a91fe210895a4f9c4666b691945a0f24dd Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 9 Feb 2024 09:24:39 +0000 Subject: [PATCH] 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 --- compiler/rustc_hir_analysis/src/coherence/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_hir_analysis/src/coherence/mod.rs b/compiler/rustc_hir_analysis/src/coherence/mod.rs index 8cf1f2c9407f6..45364225947b1 100644 --- a/compiler/rustc_hir_analysis/src/coherence/mod.rs +++ b/compiler/rustc_hir_analysis/src/coherence/mod.rs @@ -120,11 +120,11 @@ pub fn provide(providers: &mut Providers) { } fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Result<(), ErrorGuaranteed> { + let Some(impls) = tcx.all_local_trait_impls(()).get(&def_id) else { return Ok(()) }; // Trigger building the specialization graph for the trait. This will detect and report any // overlap errors. let mut res = tcx.ensure().specialization_graph_of(def_id); - let impls = tcx.hir().trait_impls(def_id); for &impl_def_id in impls { let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().instantiate_identity();