Skip to content

Commit 3e3890c

Browse files
committed
Auto merge of #90675 - camelid:cleanup-impl, r=jyn514
rustdoc: Cleanup `clean::Impl` and other parts of `clean` This PR cleans up and reduces the size of `clean::Impl`, makes some other small performance improvements, and removes some Clean impls that are either unnecessary or potentially confusing. r? `@jyn514`
2 parents b307481 + b5817fa commit 3e3890c

File tree

12 files changed

+143
-158
lines changed

12 files changed

+143
-158
lines changed

src/librustdoc/clean/auto_trait.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,17 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
7676
new_generics
7777
});
7878

79-
let negative_polarity;
79+
let polarity;
8080
let new_generics = match result {
8181
AutoTraitResult::PositiveImpl(new_generics) => {
82-
negative_polarity = false;
82+
polarity = ty::ImplPolarity::Positive;
8383
if discard_positive_impl {
8484
return None;
8585
}
8686
new_generics
8787
}
8888
AutoTraitResult::NegativeImpl => {
89-
negative_polarity = true;
89+
polarity = ty::ImplPolarity::Negative;
9090

9191
// For negative impls, we use the generic params, but *not* the predicates,
9292
// from the original type. Otherwise, the displayed impl appears to be a
@@ -115,15 +115,13 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
115115
visibility: Inherited,
116116
def_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id },
117117
kind: box ImplItem(Impl {
118-
span: Span::dummy(),
119118
unsafety: hir::Unsafety::Normal,
120119
generics: new_generics,
121120
trait_: Some(trait_ref.clean(self.cx)),
122121
for_: ty.clean(self.cx),
123122
items: Vec::new(),
124-
negative_polarity,
125-
synthetic: true,
126-
blanket_impl: None,
123+
polarity,
124+
kind: ImplKind::Auto,
127125
}),
128126
cfg: None,
129127
})

src/librustdoc/clean/blanket_impl.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
106106
visibility: Inherited,
107107
def_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
108108
kind: box ImplItem(Impl {
109-
span: Span::new(self.cx.tcx.def_span(impl_def_id)),
110109
unsafety: hir::Unsafety::Normal,
111110
generics: (
112111
self.cx.tcx.generics_of(impl_def_id),
@@ -122,11 +121,10 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
122121
.tcx
123122
.associated_items(impl_def_id)
124123
.in_definition_order()
125-
.collect::<Vec<_>>()
126-
.clean(self.cx),
127-
negative_polarity: false,
128-
synthetic: false,
129-
blanket_impl: Some(box trait_ref.self_ty().clean(self.cx)),
124+
.map(|x| x.clean(self.cx))
125+
.collect::<Vec<_>>(),
126+
polarity: ty::ImplPolarity::Positive,
127+
kind: ImplKind::Blanket(box trait_ref.self_ty().clean(self.cx)),
130128
}),
131129
cfg: None,
132130
});

src/librustdoc/clean/inline.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ use rustc_middle::ty::{self, TyCtxt};
1414
use rustc_span::hygiene::MacroKind;
1515
use rustc_span::symbol::{kw, sym, Symbol};
1616

17-
use crate::clean::{self, utils, Attributes, AttributesExt, ItemId, NestedAttributesExt, Type};
17+
use crate::clean::{
18+
self, utils, Attributes, AttributesExt, ImplKind, ItemId, NestedAttributesExt, Type,
19+
};
1820
use crate::core::DocContext;
1921
use crate::formats::item_type::ItemType;
2022

@@ -242,7 +244,7 @@ fn build_enum(cx: &mut DocContext<'_>, did: DefId) -> clean::Enum {
242244
clean::Enum {
243245
generics: (cx.tcx.generics_of(did), predicates).clean(cx),
244246
variants_stripped: false,
245-
variants: cx.tcx.adt_def(did).variants.clean(cx),
247+
variants: cx.tcx.adt_def(did).variants.iter().map(|v| v.clean(cx)).collect(),
246248
}
247249
}
248250

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

265-
clean::Union {
266-
generics: (cx.tcx.generics_of(did), predicates).clean(cx),
267-
fields: variant.fields.clean(cx),
268-
fields_stripped: false,
269-
}
267+
let generics = (cx.tcx.generics_of(did), predicates).clean(cx);
268+
let fields = variant.fields.iter().map(|x| x.clean(cx)).collect();
269+
clean::Union { generics, fields, fields_stripped: false }
270270
}
271271

272272
fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::Typedef {
@@ -446,7 +446,7 @@ crate fn build_impl(
446446
),
447447
};
448448
let polarity = tcx.impl_polarity(did);
449-
let trait_ = associated_trait.clean(cx);
449+
let trait_ = associated_trait.map(|t| t.clean(cx));
450450
if trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait() {
451451
super::build_deref_target_impls(cx, &trait_items, ret);
452452
}
@@ -490,15 +490,13 @@ crate fn build_impl(
490490
did,
491491
None,
492492
clean::ImplItem(clean::Impl {
493-
span: clean::types::rustc_span(did, cx.tcx),
494493
unsafety: hir::Unsafety::Normal,
495494
generics,
496495
trait_,
497496
for_,
498497
items: trait_items,
499-
negative_polarity: polarity.clean(cx),
500-
synthetic: false,
501-
blanket_impl: None,
498+
polarity,
499+
kind: ImplKind::Normal,
502500
}),
503501
box merged_attrs,
504502
cx,

0 commit comments

Comments
 (0)