Skip to content

Commit

Permalink
rustdoc: Box GenericArg::Const to reduce enum size
Browse files Browse the repository at this point in the history
  • Loading branch information
camelid committed Sep 3, 2021
1 parent fcce644 commit 5c0e6c1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Expand Up @@ -1787,7 +1787,7 @@ impl Clean<GenericArgs> for hir::GenericArgs<'_> {
}
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
hir::GenericArg::Type(ty) => GenericArg::Type(ty.clean(cx)),
hir::GenericArg::Const(ct) => GenericArg::Const(ct.clean(cx)),
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(ct.clean(cx))),
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
})
.collect(),
Expand Down
7 changes: 6 additions & 1 deletion src/librustdoc/clean/types.rs
Expand Up @@ -2012,10 +2012,15 @@ impl Path {
crate enum GenericArg {
Lifetime(Lifetime),
Type(Type),
Const(Constant),
Const(Box<Constant>),
Infer,
}

// `GenericArg` can occur many times in a single `Path`, so make sure it
// doesn't increase in size unexpectedly.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(GenericArg, 80);

#[derive(Clone, PartialEq, Eq, Debug, Hash)]
crate enum GenericArgs {
AngleBracketed { args: Vec<GenericArg>, bindings: Vec<TypeBinding> },
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/utils.rs
Expand Up @@ -121,7 +121,7 @@ fn external_generic_args(
ty_kind = Some(ty.kind());
Some(GenericArg::Type(ty.clean(cx)))
}
GenericArgKind::Const(ct) => Some(GenericArg::Const(ct.clean(cx))),
GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
})
.collect();

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/json/conversions.rs
Expand Up @@ -139,7 +139,7 @@ impl FromWithTcx<clean::GenericArg> for GenericArg {
match arg {
Lifetime(l) => GenericArg::Lifetime(l.0.to_string()),
Type(t) => GenericArg::Type(t.into_tcx(tcx)),
Const(c) => GenericArg::Const(c.into_tcx(tcx)),
Const(box c) => GenericArg::Const(c.into_tcx(tcx)),
Infer => GenericArg::Infer,
}
}
Expand Down

0 comments on commit 5c0e6c1

Please sign in to comment.