Skip to content

Commit b89e01c

Browse files
committed
Auto merge of #88574 - camelid:box-genericarg-const, r=GuillaumeGomez
rustdoc: Box `GenericArg::Const` to reduce enum size This should reduce the amount of memory allocated in the common cases where the `GenericArg` is a lifetime or type.
2 parents 226e181 + 5c0e6c1 commit b89e01c

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1789,7 +1789,7 @@ impl Clean<GenericArgs> for hir::GenericArgs<'_> {
17891789
}
17901790
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
17911791
hir::GenericArg::Type(ty) => GenericArg::Type(ty.clean(cx)),
1792-
hir::GenericArg::Const(ct) => GenericArg::Const(ct.clean(cx)),
1792+
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(ct.clean(cx))),
17931793
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
17941794
})
17951795
.collect(),

src/librustdoc/clean/types.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -2012,10 +2012,15 @@ impl Path {
20122012
crate enum GenericArg {
20132013
Lifetime(Lifetime),
20142014
Type(Type),
2015-
Const(Constant),
2015+
Const(Box<Constant>),
20162016
Infer,
20172017
}
20182018

2019+
// `GenericArg` can occur many times in a single `Path`, so make sure it
2020+
// doesn't increase in size unexpectedly.
2021+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
2022+
rustc_data_structures::static_assert_size!(GenericArg, 80);
2023+
20192024
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
20202025
crate enum GenericArgs {
20212026
AngleBracketed { args: Vec<GenericArg>, bindings: Vec<TypeBinding> },

src/librustdoc/clean/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn external_generic_args(
121121
ty_kind = Some(ty.kind());
122122
Some(GenericArg::Type(ty.clean(cx)))
123123
}
124-
GenericArgKind::Const(ct) => Some(GenericArg::Const(ct.clean(cx))),
124+
GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
125125
})
126126
.collect();
127127

src/librustdoc/json/conversions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl FromWithTcx<clean::GenericArg> for GenericArg {
139139
match arg {
140140
Lifetime(l) => GenericArg::Lifetime(l.0.to_string()),
141141
Type(t) => GenericArg::Type(t.into_tcx(tcx)),
142-
Const(c) => GenericArg::Const(c.into_tcx(tcx)),
142+
Const(box c) => GenericArg::Const(c.into_tcx(tcx)),
143143
Infer => GenericArg::Infer,
144144
}
145145
}

0 commit comments

Comments
 (0)