Skip to content

rustdoc: Cleanup clean::Impl and other parts of clean #90675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 8, 2021
12 changes: 5 additions & 7 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
new_generics
});

let negative_polarity;
let polarity;
let new_generics = match result {
AutoTraitResult::PositiveImpl(new_generics) => {
negative_polarity = false;
polarity = ty::ImplPolarity::Positive;
if discard_positive_impl {
return None;
}
new_generics
}
AutoTraitResult::NegativeImpl => {
negative_polarity = true;
polarity = ty::ImplPolarity::Negative;

// For negative impls, we use the generic params, but *not* the predicates,
// from the original type. Otherwise, the displayed impl appears to be a
Expand Down Expand Up @@ -115,15 +115,13 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
visibility: Inherited,
def_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id },
kind: box ImplItem(Impl {
span: Span::dummy(),
unsafety: hir::Unsafety::Normal,
generics: new_generics,
trait_: Some(trait_ref.clean(self.cx)),
for_: ty.clean(self.cx),
items: Vec::new(),
negative_polarity,
synthetic: true,
blanket_impl: None,
polarity,
kind: ImplKind::Auto,
}),
cfg: None,
})
Expand Down
10 changes: 4 additions & 6 deletions src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
visibility: Inherited,
def_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
kind: box ImplItem(Impl {
span: Span::new(self.cx.tcx.def_span(impl_def_id)),
unsafety: hir::Unsafety::Normal,
generics: (
self.cx.tcx.generics_of(impl_def_id),
Expand All @@ -122,11 +121,10 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
.tcx
.associated_items(impl_def_id)
.in_definition_order()
.collect::<Vec<_>>()
.clean(self.cx),
negative_polarity: false,
synthetic: false,
blanket_impl: Some(box trait_ref.self_ty().clean(self.cx)),
.map(|x| x.clean(self.cx))
.collect::<Vec<_>>(),
polarity: ty::ImplPolarity::Positive,
kind: ImplKind::Blanket(box trait_ref.self_ty().clean(self.cx)),
}),
cfg: None,
});
Expand Down
24 changes: 11 additions & 13 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use rustc_middle::ty::{self, TyCtxt};
use rustc_span::hygiene::MacroKind;
use rustc_span::symbol::{kw, sym, Symbol};

use crate::clean::{self, utils, Attributes, AttributesExt, ItemId, NestedAttributesExt, Type};
use crate::clean::{
self, utils, Attributes, AttributesExt, ImplKind, ItemId, NestedAttributesExt, Type,
};
use crate::core::DocContext;
use crate::formats::item_type::ItemType;

Expand Down Expand Up @@ -242,7 +244,7 @@ fn build_enum(cx: &mut DocContext<'_>, did: DefId) -> clean::Enum {
clean::Enum {
generics: (cx.tcx.generics_of(did), predicates).clean(cx),
variants_stripped: false,
variants: cx.tcx.adt_def(did).variants.clean(cx),
variants: cx.tcx.adt_def(did).variants.iter().map(|v| v.clean(cx)).collect(),
}
}

Expand All @@ -253,7 +255,7 @@ fn build_struct(cx: &mut DocContext<'_>, did: DefId) -> clean::Struct {
clean::Struct {
struct_type: variant.ctor_kind,
generics: (cx.tcx.generics_of(did), predicates).clean(cx),
fields: variant.fields.clean(cx),
fields: variant.fields.iter().map(|x| x.clean(cx)).collect(),
fields_stripped: false,
}
}
Expand All @@ -262,11 +264,9 @@ fn build_union(cx: &mut DocContext<'_>, did: DefId) -> clean::Union {
let predicates = cx.tcx.explicit_predicates_of(did);
let variant = cx.tcx.adt_def(did).non_enum_variant();

clean::Union {
generics: (cx.tcx.generics_of(did), predicates).clean(cx),
fields: variant.fields.clean(cx),
fields_stripped: false,
}
let generics = (cx.tcx.generics_of(did), predicates).clean(cx);
let fields = variant.fields.iter().map(|x| x.clean(cx)).collect();
clean::Union { generics, fields, fields_stripped: false }
}

fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::Typedef {
Expand Down Expand Up @@ -446,7 +446,7 @@ crate fn build_impl(
),
};
let polarity = tcx.impl_polarity(did);
let trait_ = associated_trait.clean(cx);
let trait_ = associated_trait.map(|t| t.clean(cx));
if trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait() {
super::build_deref_target_impls(cx, &trait_items, ret);
}
Expand Down Expand Up @@ -490,15 +490,13 @@ crate fn build_impl(
did,
None,
clean::ImplItem(clean::Impl {
span: clean::types::rustc_span(did, cx.tcx),
unsafety: hir::Unsafety::Normal,
generics,
trait_,
for_,
items: trait_items,
negative_polarity: polarity.clean(cx),
synthetic: false,
blanket_impl: None,
polarity,
kind: ImplKind::Normal,
}),
box merged_attrs,
cx,
Expand Down
Loading