Skip to content

Commit

Permalink
Remove unnecessary provided_trait_methods field from Impl
Browse files Browse the repository at this point in the history
It can be calculated on-demand.
  • Loading branch information
jyn514 committed May 1, 2021
1 parent 8a9fa36 commit b1f5917
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 30 deletions.
1 change: 0 additions & 1 deletion src/librustdoc/clean/auto_trait.rs
Expand Up @@ -118,7 +118,6 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
span: Span::dummy(),
unsafety: hir::Unsafety::Normal,
generics: new_generics,
provided_trait_methods: Default::default(),
trait_: Some(trait_ref.clean(self.cx).get_trait_type().unwrap()),
for_: ty.clean(self.cx),
items: Vec::new(),
Expand Down
7 changes: 0 additions & 7 deletions src/librustdoc/clean/blanket_impl.rs
Expand Up @@ -92,12 +92,6 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
}

self.cx.generated_synthetics.insert((ty, trait_def_id));
let provided_trait_methods = self
.cx
.tcx
.provided_trait_methods(trait_def_id)
.map(|meth| meth.ident.name)
.collect();

impls.push(Item {
name: None,
Expand All @@ -112,7 +106,6 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
self.cx.tcx.explicit_predicates_of(impl_def_id),
)
.clean(self.cx),
provided_trait_methods,
// FIXME(eddyb) compute both `trait_` and `for_` from
// the post-inference `trait_ref`, as it's more accurate.
trait_: Some(trait_ref.clean(self.cx).get_trait_type().unwrap()),
Expand Down
9 changes: 1 addition & 8 deletions src/librustdoc/clean/inline.rs
Expand Up @@ -414,24 +414,17 @@ crate fn build_impl(
record_extern_trait(cx, trait_did);
}

let provided = trait_
.def_id()
.map(|did| tcx.provided_trait_methods(did).map(|meth| meth.ident.name).collect())
.unwrap_or_default();

debug!("build_impl: impl {:?} for {:?}", trait_.def_id(), for_.def_id());

let (merged_attrs, cfg) = merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs);
debug!("merged_attrs={:?}", merged_attrs);

debug!("build_impl: impl {:?} for {:?}", trait_.def_id(), for_.def_id());
ret.push(clean::Item::from_def_id_and_attrs_and_parts(
did,
None,
clean::ImplItem(clean::Impl {
span: clean::types::rustc_span(did, cx.tcx),
unsafety: hir::Unsafety::Normal,
generics,
provided_trait_methods: provided,
trait_,
for_,
items: trait_items,
Expand Down
6 changes: 0 additions & 6 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -1930,11 +1930,6 @@ fn clean_impl(impl_: &hir::Impl<'_>, hir_id: hir::HirId, cx: &mut DocContext<'_>
build_deref_target_impls(cx, &items, &mut ret);
}

let provided: FxHashSet<Symbol> = trait_
.def_id()
.map(|did| tcx.provided_trait_methods(did).map(|meth| meth.ident.name).collect())
.unwrap_or_default();

let for_ = impl_.self_ty.clean(cx);
let type_alias = for_.def_id().and_then(|did| match tcx.def_kind(did) {
DefKind::TyAlias => Some(tcx.type_of(did).clean(cx)),
Expand All @@ -1945,7 +1940,6 @@ fn clean_impl(impl_: &hir::Impl<'_>, hir_id: hir::HirId, cx: &mut DocContext<'_>
span: types::rustc_span(tcx.hir().local_def_id(hir_id).to_def_id(), tcx),
unsafety: impl_.unsafety,
generics: impl_.generics.clean(cx),
provided_trait_methods: provided.clone(),
trait_,
for_,
items,
Expand Down
10 changes: 9 additions & 1 deletion src/librustdoc/clean/types.rs
Expand Up @@ -2150,7 +2150,6 @@ crate struct Impl {
crate span: Span,
crate unsafety: hir::Unsafety,
crate generics: Generics,
crate provided_trait_methods: FxHashSet<Symbol>,
crate trait_: Option<Type>,
crate for_: Type,
crate items: Vec<Item>,
Expand All @@ -2159,6 +2158,15 @@ crate struct Impl {
crate blanket_impl: Option<Type>,
}

impl Impl {
crate fn provided_trait_methods(&self, tcx: TyCtxt<'_>) -> FxHashSet<Symbol> {
self.trait_
.def_id()
.map(|did| tcx.provided_trait_methods(did).map(|meth| meth.ident.name).collect())
.unwrap_or_default()
}
}

#[derive(Clone, Debug)]
crate struct Import {
crate kind: ImportKind,
Expand Down
6 changes: 4 additions & 2 deletions src/librustdoc/html/render/mod.rs
Expand Up @@ -726,7 +726,8 @@ fn render_impls(
.iter()
.map(|i| {
let did = i.trait_did_full(cache).unwrap();
let assoc_link = AssocItemLink::GotoSource(did, &i.inner_impl().provided_trait_methods);
let provided_trait_methods = i.inner_impl().provided_trait_methods(tcx);
let assoc_link = AssocItemLink::GotoSource(did, &provided_trait_methods);
let mut buffer = if w.is_for_html() { Buffer::html() } else { Buffer::new() };
render_impl(
&mut buffer,
Expand Down Expand Up @@ -1490,7 +1491,8 @@ fn render_impl(
continue;
}
let did = i.trait_.as_ref().unwrap().def_id_full(cx.cache()).unwrap();
let assoc_link = AssocItemLink::GotoSource(did, &i.provided_trait_methods);
let provided_methods = i.provided_trait_methods(cx.tcx());
let assoc_link = AssocItemLink::GotoSource(did, &provided_methods);

doc_impl_item(
w,
Expand Down
7 changes: 3 additions & 4 deletions src/librustdoc/html/render/print_item.rs
Expand Up @@ -669,10 +669,9 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
write_small_section_header(w, "foreign-impls", "Implementations on Foreign Types", "");

for implementor in foreign {
let assoc_link = AssocItemLink::GotoSource(
implementor.impl_item.def_id,
&implementor.inner_impl().provided_trait_methods,
);
let provided_methods = implementor.inner_impl().provided_trait_methods(cx.tcx());
let assoc_link =
AssocItemLink::GotoSource(implementor.impl_item.def_id, &provided_methods);
render_impl(
w,
cx,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/json/conversions.rs
Expand Up @@ -453,10 +453,10 @@ impl FromWithTcx<clean::Trait> for Trait {

impl FromWithTcx<clean::Impl> for Impl {
fn from_tcx(impl_: clean::Impl, tcx: TyCtxt<'_>) -> Self {
let provided_trait_methods = impl_.provided_trait_methods(tcx);
let clean::Impl {
unsafety,
generics,
provided_trait_methods,
trait_,
for_,
items,
Expand Down

0 comments on commit b1f5917

Please sign in to comment.