From 6f06b761b991f5c4b714c6935781114dce44637a Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 30 Mar 2021 12:28:33 -0400 Subject: [PATCH] Only look at blanket impls in `get_blanket_impls` --- compiler/rustc_middle/src/ty/trait_def.rs | 6 ++++++ src/librustdoc/clean/blanket_impl.rs | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_middle/src/ty/trait_def.rs b/compiler/rustc_middle/src/ty/trait_def.rs index ce17a724e25..33065bc3a7b 100644 --- a/compiler/rustc_middle/src/ty/trait_def.rs +++ b/compiler/rustc_middle/src/ty/trait_def.rs @@ -69,6 +69,12 @@ pub struct TraitImpls { non_blanket_impls: FxHashMap>, } +impl TraitImpls { + pub fn blanket_impls(&self) -> &[DefId] { + self.blanket_impls.as_slice() + } +} + impl<'tcx> TraitDef { pub fn new( def_id: DefId, diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 1bbaa60fe96..f7e08d10401 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -26,7 +26,9 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { { continue; } - self.cx.tcx.for_each_relevant_impl(trait_def_id, ty, |impl_def_id| { + // NOTE: doesn't use `for_each_relevant_impl` to avoid looking at anything besides blanket impls + let trait_impls = self.cx.tcx.trait_impls_of(trait_def_id); + for &impl_def_id in trait_impls.blanket_impls() { debug!( "get_blanket_impls: Considering impl for trait '{:?}' {:?}", trait_def_id, impl_def_id @@ -86,7 +88,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { may_apply, trait_ref, ty ); if !may_apply { - return; + continue; } self.cx.generated_synthetics.insert((ty, trait_def_id)); @@ -127,7 +129,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { blanket_impl: Some(trait_ref.self_ty().clean(self.cx)), }), }); - }); + } } impls }