Skip to content

Commit c16c458

Browse files
authored
Unrolled build for rust-lang#128263
Rollup merge of rust-lang#128263 - notriddle:notriddle/clean-up-again, r=GuillaumeGomez rustdoc: use strategic ThinVec/Box to shrink `clean::ItemKind`
2 parents 1b51d80 + 3abf0ba commit c16c458

File tree

10 files changed

+120
-89
lines changed

10 files changed

+120
-89
lines changed

src/librustdoc/clean/inline.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ pub(crate) fn try_inline(
131131
Res::Def(DefKind::Const, did) => {
132132
record_extern_fqn(cx, did, ItemType::Constant);
133133
cx.with_param_env(did, |cx| {
134-
let (generics, ty, ct) = build_const_item(cx, did);
135-
clean::ConstantItem(generics, Box::new(ty), ct)
134+
let ct = build_const_item(cx, did);
135+
clean::ConstantItem(Box::new(ct))
136136
})
137137
}
138138
Res::Def(DefKind::Macro(kind), did) => {
@@ -720,10 +720,7 @@ pub(crate) fn print_inlined_const(tcx: TyCtxt<'_>, did: DefId) -> String {
720720
}
721721
}
722722

723-
fn build_const_item(
724-
cx: &mut DocContext<'_>,
725-
def_id: DefId,
726-
) -> (clean::Generics, clean::Type, clean::Constant) {
723+
fn build_const_item(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant {
727724
let mut generics =
728725
clean_ty_generics(cx, cx.tcx.generics_of(def_id), cx.tcx.explicit_predicates_of(def_id));
729726
clean::simplify::move_bounds_to_generic_parameters(&mut generics);
@@ -733,17 +730,17 @@ fn build_const_item(
733730
None,
734731
None,
735732
);
736-
(generics, ty, clean::Constant { kind: clean::ConstantKind::Extern { def_id } })
733+
clean::Constant { generics, type_: ty, kind: clean::ConstantKind::Extern { def_id } }
737734
}
738735

739736
fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::Static {
740737
clean::Static {
741-
type_: clean_middle_ty(
738+
type_: Box::new(clean_middle_ty(
742739
ty::Binder::dummy(cx.tcx.type_of(did).instantiate_identity()),
743740
cx,
744741
Some(did),
745742
None,
746-
),
743+
)),
747744
mutability: if mutable { Mutability::Mut } else { Mutability::Not },
748745
expr: None,
749746
}

src/librustdoc/clean/mod.rs

+35-34
Original file line numberDiff line numberDiff line change
@@ -287,23 +287,21 @@ fn clean_lifetime<'tcx>(lifetime: &hir::Lifetime, cx: &mut DocContext<'tcx>) ->
287287
pub(crate) fn clean_const<'tcx>(
288288
constant: &hir::ConstArg<'tcx>,
289289
_cx: &mut DocContext<'tcx>,
290-
) -> Constant {
290+
) -> ConstantKind {
291291
match &constant.kind {
292292
hir::ConstArgKind::Path(qpath) => {
293-
Constant { kind: ConstantKind::Path { path: qpath_to_string(&qpath).into() } }
294-
}
295-
hir::ConstArgKind::Anon(anon) => {
296-
Constant { kind: ConstantKind::Anonymous { body: anon.body } }
293+
ConstantKind::Path { path: qpath_to_string(&qpath).into() }
297294
}
295+
hir::ConstArgKind::Anon(anon) => ConstantKind::Anonymous { body: anon.body },
298296
}
299297
}
300298

301299
pub(crate) fn clean_middle_const<'tcx>(
302300
constant: ty::Binder<'tcx, ty::Const<'tcx>>,
303301
_cx: &mut DocContext<'tcx>,
304-
) -> Constant {
302+
) -> ConstantKind {
305303
// FIXME: instead of storing the stringified expression, store `self` directly instead.
306-
Constant { kind: ConstantKind::TyConst { expr: constant.skip_binder().to_string().into() } }
304+
ConstantKind::TyConst { expr: constant.skip_binder().to_string().into() }
307305
}
308306

309307
pub(crate) fn clean_middle_region<'tcx>(region: ty::Region<'tcx>) -> Option<Lifetime> {
@@ -1230,14 +1228,11 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
12301228
let local_did = trait_item.owner_id.to_def_id();
12311229
cx.with_param_env(local_did, |cx| {
12321230
let inner = match trait_item.kind {
1233-
hir::TraitItemKind::Const(ty, Some(default)) => {
1234-
let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx));
1235-
AssocConstItem(
1236-
generics,
1237-
Box::new(clean_ty(ty, cx)),
1238-
ConstantKind::Local { def_id: local_did, body: default },
1239-
)
1240-
}
1231+
hir::TraitItemKind::Const(ty, Some(default)) => AssocConstItem(Box::new(Constant {
1232+
generics: enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)),
1233+
kind: ConstantKind::Local { def_id: local_did, body: default },
1234+
type_: clean_ty(ty, cx),
1235+
})),
12411236
hir::TraitItemKind::Const(ty, None) => {
12421237
let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx));
12431238
TyAssocConstItem(generics, Box::new(clean_ty(ty, cx)))
@@ -1282,11 +1277,11 @@ pub(crate) fn clean_impl_item<'tcx>(
12821277
let local_did = impl_.owner_id.to_def_id();
12831278
cx.with_param_env(local_did, |cx| {
12841279
let inner = match impl_.kind {
1285-
hir::ImplItemKind::Const(ty, expr) => {
1286-
let generics = clean_generics(impl_.generics, cx);
1287-
let default = ConstantKind::Local { def_id: local_did, body: expr };
1288-
AssocConstItem(generics, Box::new(clean_ty(ty, cx)), default)
1289-
}
1280+
hir::ImplItemKind::Const(ty, expr) => AssocConstItem(Box::new(Constant {
1281+
generics: clean_generics(impl_.generics, cx),
1282+
kind: ConstantKind::Local { def_id: local_did, body: expr },
1283+
type_: clean_ty(ty, cx),
1284+
})),
12901285
hir::ImplItemKind::Fn(ref sig, body) => {
12911286
let m = clean_function(cx, sig, impl_.generics, FunctionArgs::Body(body));
12921287
let defaultness = cx.tcx.defaultness(impl_.owner_id);
@@ -1320,12 +1315,12 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13201315
let tcx = cx.tcx;
13211316
let kind = match assoc_item.kind {
13221317
ty::AssocKind::Const => {
1323-
let ty = Box::new(clean_middle_ty(
1318+
let ty = clean_middle_ty(
13241319
ty::Binder::dummy(tcx.type_of(assoc_item.def_id).instantiate_identity()),
13251320
cx,
13261321
Some(assoc_item.def_id),
13271322
None,
1328-
));
1323+
);
13291324

13301325
let mut generics = clean_ty_generics(
13311326
cx,
@@ -1339,9 +1334,13 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13391334
ty::TraitContainer => tcx.defaultness(assoc_item.def_id).has_value(),
13401335
};
13411336
if provided {
1342-
AssocConstItem(generics, ty, ConstantKind::Extern { def_id: assoc_item.def_id })
1337+
AssocConstItem(Box::new(Constant {
1338+
generics,
1339+
kind: ConstantKind::Extern { def_id: assoc_item.def_id },
1340+
type_: ty,
1341+
}))
13431342
} else {
1344-
TyAssocConstItem(generics, ty)
1343+
TyAssocConstItem(generics, Box::new(ty))
13451344
}
13461345
}
13471346
ty::AssocKind::Fn => {
@@ -1397,7 +1396,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13971396
{
13981397
true
13991398
}
1400-
(GenericParamDefKind::Const { .. }, GenericArg::Const(c)) => match &c.kind {
1399+
(GenericParamDefKind::Const { .. }, GenericArg::Const(c)) => match &**c {
14011400
ConstantKind::TyConst { expr } => **expr == *param.name.as_str(),
14021401
_ => false,
14031402
},
@@ -2744,14 +2743,16 @@ fn clean_maybe_renamed_item<'tcx>(
27442743
let mut name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id()));
27452744
cx.with_param_env(def_id, |cx| {
27462745
let kind = match item.kind {
2747-
ItemKind::Static(ty, mutability, body_id) => {
2748-
StaticItem(Static { type_: clean_ty(ty, cx), mutability, expr: Some(body_id) })
2749-
}
2750-
ItemKind::Const(ty, generics, body_id) => ConstantItem(
2751-
clean_generics(generics, cx),
2752-
Box::new(clean_ty(ty, cx)),
2753-
Constant { kind: ConstantKind::Local { body: body_id, def_id } },
2754-
),
2746+
ItemKind::Static(ty, mutability, body_id) => StaticItem(Static {
2747+
type_: Box::new(clean_ty(ty, cx)),
2748+
mutability,
2749+
expr: Some(body_id),
2750+
}),
2751+
ItemKind::Const(ty, generics, body_id) => ConstantItem(Box::new(Constant {
2752+
generics: clean_generics(generics, cx),
2753+
type_: clean_ty(ty, cx),
2754+
kind: ConstantKind::Local { body: body_id, def_id },
2755+
})),
27552756
ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy {
27562757
bounds: ty.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
27572758
generics: clean_generics(ty.generics, cx),
@@ -3109,7 +3110,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
31093110
ForeignFunctionItem(Box::new(Function { decl, generics }), safety)
31103111
}
31113112
hir::ForeignItemKind::Static(ty, mutability, safety) => ForeignStaticItem(
3112-
Static { type_: clean_ty(ty, cx), mutability, expr: None },
3113+
Static { type_: Box::new(clean_ty(ty, cx)), mutability, expr: None },
31133114
safety,
31143115
),
31153116
hir::ForeignItemKind::Type => ForeignTypeItem,

src/librustdoc/clean/types.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,9 @@ pub(crate) enum ItemKind {
852852
PrimitiveItem(PrimitiveType),
853853
/// A required associated constant in a trait declaration.
854854
TyAssocConstItem(Generics, Box<Type>),
855-
ConstantItem(Generics, Box<Type>, Constant),
855+
ConstantItem(Box<Constant>),
856856
/// An associated constant in a trait impl or a provided one in a trait declaration.
857-
AssocConstItem(Generics, Box<Type>, ConstantKind),
857+
AssocConstItem(Box<Constant>),
858858
/// A required associated type in a trait declaration.
859859
///
860860
/// The bounds may be non-empty if there is a `where` clause.
@@ -888,7 +888,7 @@ impl ItemKind {
888888
| TypeAliasItem(_)
889889
| OpaqueTyItem(_)
890890
| StaticItem(_)
891-
| ConstantItem(_, _, _)
891+
| ConstantItem(_)
892892
| TraitAliasItem(_)
893893
| TyMethodItem(_)
894894
| MethodItem(_, _)
@@ -922,7 +922,7 @@ impl ItemKind {
922922
| TypeAliasItem(_)
923923
| OpaqueTyItem(_)
924924
| StaticItem(_)
925-
| ConstantItem(_, _, _)
925+
| ConstantItem(_)
926926
| TraitAliasItem(_)
927927
| ForeignFunctionItem(_, _)
928928
| ForeignStaticItem(_, _)
@@ -2050,7 +2050,7 @@ impl From<hir::PrimTy> for PrimitiveType {
20502050
pub(crate) struct Struct {
20512051
pub(crate) ctor_kind: Option<CtorKind>,
20522052
pub(crate) generics: Generics,
2053-
pub(crate) fields: Vec<Item>,
2053+
pub(crate) fields: ThinVec<Item>,
20542054
}
20552055

20562056
impl Struct {
@@ -2076,7 +2076,7 @@ impl Union {
20762076
/// only as a variant in an enum.
20772077
#[derive(Clone, Debug)]
20782078
pub(crate) struct VariantStruct {
2079-
pub(crate) fields: Vec<Item>,
2079+
pub(crate) fields: ThinVec<Item>,
20802080
}
20812081

20822082
impl VariantStruct {
@@ -2110,7 +2110,7 @@ pub(crate) struct Variant {
21102110
#[derive(Clone, Debug)]
21112111
pub(crate) enum VariantKind {
21122112
CLike,
2113-
Tuple(Vec<Item>),
2113+
Tuple(ThinVec<Item>),
21142114
Struct(VariantStruct),
21152115
}
21162116

@@ -2246,7 +2246,7 @@ impl Path {
22462246
pub(crate) enum GenericArg {
22472247
Lifetime(Lifetime),
22482248
Type(Type),
2249-
Const(Box<Constant>),
2249+
Const(Box<ConstantKind>),
22502250
Infer,
22512251
}
22522252

@@ -2359,20 +2359,22 @@ pub(crate) struct BareFunctionDecl {
23592359

23602360
#[derive(Clone, Debug)]
23612361
pub(crate) struct Static {
2362-
pub(crate) type_: Type,
2362+
pub(crate) type_: Box<Type>,
23632363
pub(crate) mutability: Mutability,
23642364
pub(crate) expr: Option<BodyId>,
23652365
}
23662366

23672367
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
23682368
pub(crate) struct Constant {
2369+
pub(crate) generics: Generics,
23692370
pub(crate) kind: ConstantKind,
2371+
pub(crate) type_: Type,
23702372
}
23712373

23722374
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
23732375
pub(crate) enum Term {
23742376
Type(Type),
2375-
Constant(Constant),
2377+
Constant(ConstantKind),
23762378
}
23772379

23782380
impl Term {
@@ -2594,7 +2596,7 @@ mod size_asserts {
25942596
static_assert_size!(GenericParamDef, 40);
25952597
static_assert_size!(Generics, 16);
25962598
static_assert_size!(Item, 56);
2597-
static_assert_size!(ItemKind, 56);
2599+
static_assert_size!(ItemKind, 48);
25982600
static_assert_size!(PathSegment, 40);
25992601
static_assert_size!(Type, 32);
26002602
// tidy-alphabetical-end

src/librustdoc/fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub(crate) trait DocFolder: Sized {
7979
| FunctionItem(_)
8080
| OpaqueTyItem(_)
8181
| StaticItem(_)
82-
| ConstantItem(_, _, _)
82+
| ConstantItem(..)
8383
| TraitAliasItem(_)
8484
| TyMethodItem(_)
8585
| MethodItem(_, _)

src/librustdoc/html/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ impl clean::Lifetime {
375375
}
376376
}
377377

378-
impl clean::Constant {
378+
impl clean::ConstantKind {
379379
pub(crate) fn print(&self, tcx: TyCtxt<'_>) -> impl Display + '_ {
380380
let expr = self.expr(tcx);
381381
display_fn(

src/librustdoc/html/render/mod.rs

+44-23
Original file line numberDiff line numberDiff line change
@@ -1090,22 +1090,26 @@ fn render_assoc_item(
10901090
clean::MethodItem(m, _) => {
10911091
assoc_method(w, item, &m.generics, &m.decl, link, parent, cx, render_mode)
10921092
}
1093-
kind @ (clean::TyAssocConstItem(generics, ty) | clean::AssocConstItem(generics, ty, _)) => {
1094-
assoc_const(
1095-
w,
1096-
item,
1097-
generics,
1098-
ty,
1099-
match kind {
1100-
clean::TyAssocConstItem(..) => None,
1101-
clean::AssocConstItem(.., default) => Some(default),
1102-
_ => unreachable!(),
1103-
},
1104-
link,
1105-
if parent == ItemType::Trait { 4 } else { 0 },
1106-
cx,
1107-
)
1108-
}
1093+
clean::TyAssocConstItem(generics, ty) => assoc_const(
1094+
w,
1095+
item,
1096+
generics,
1097+
ty,
1098+
None,
1099+
link,
1100+
if parent == ItemType::Trait { 4 } else { 0 },
1101+
cx,
1102+
),
1103+
clean::AssocConstItem(ci) => assoc_const(
1104+
w,
1105+
item,
1106+
&ci.generics,
1107+
&ci.type_,
1108+
Some(&ci.kind),
1109+
link,
1110+
if parent == ItemType::Trait { 4 } else { 0 },
1111+
cx,
1112+
),
11091113
clean::TyAssocTypeItem(ref generics, ref bounds) => assoc_type(
11101114
w,
11111115
item,
@@ -1690,8 +1694,7 @@ fn render_impl(
16901694
w.write_str("</h4></section>");
16911695
}
16921696
}
1693-
kind @ (clean::TyAssocConstItem(generics, ty)
1694-
| clean::AssocConstItem(generics, ty, _)) => {
1697+
clean::TyAssocConstItem(generics, ty) => {
16951698
let source_id = format!("{item_type}.{name}");
16961699
let id = cx.derive_id(&source_id);
16971700
write!(w, "<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">");
@@ -1706,11 +1709,29 @@ fn render_impl(
17061709
item,
17071710
generics,
17081711
ty,
1709-
match kind {
1710-
clean::TyAssocConstItem(..) => None,
1711-
clean::AssocConstItem(.., default) => Some(default),
1712-
_ => unreachable!(),
1713-
},
1712+
None,
1713+
link.anchor(if trait_.is_some() { &source_id } else { &id }),
1714+
0,
1715+
cx,
1716+
);
1717+
w.write_str("</h4></section>");
1718+
}
1719+
clean::AssocConstItem(ci) => {
1720+
let source_id = format!("{item_type}.{name}");
1721+
let id = cx.derive_id(&source_id);
1722+
write!(w, "<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">");
1723+
render_rightside(w, cx, item, render_mode);
1724+
if trait_.is_some() {
1725+
// Anchors are only used on trait impls.
1726+
write!(w, "<a href=\"#{id}\" class=\"anchor\">§</a>");
1727+
}
1728+
w.write_str("<h4 class=\"code-header\">");
1729+
assoc_const(
1730+
w,
1731+
item,
1732+
&ci.generics,
1733+
&ci.type_,
1734+
Some(&ci.kind),
17141735
link.anchor(if trait_.is_some() { &source_id } else { &id }),
17151736
0,
17161737
cx,

0 commit comments

Comments
 (0)