1
Fork 0

Auto merge of #104013 - notriddle:notriddle/rustdoc-sizeof, r=GuillaumeGomez

rustdoc: use `ThinVec` and `Box<str>` to shrink `clean::ItemKind`
This commit is contained in:
bors 2022-11-08 00:02:45 +00:00
commit 6184a963f7
5 changed files with 22 additions and 28 deletions

View file

@ -21,7 +21,7 @@ use rustc_middle::ty::{self, DefIdTree, TyCtxt};
use rustc_span::symbol::{kw, sym, Symbol};
use std::fmt::Write as _;
use std::mem;
use thin_vec::ThinVec;
use thin_vec::{thin_vec, ThinVec};
#[cfg(test)]
mod tests;
@ -136,7 +136,7 @@ pub(super) fn external_path<'tcx>(
let name = cx.tcx.item_name(did);
Path {
res: Res::Def(def_kind, did),
segments: vec![PathSegment {
segments: thin_vec![PathSegment {
name,
args: external_generic_args(cx, did, has_self, bindings, substs),
}],
@ -242,19 +242,13 @@ pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String {
s
}
_ => {
let mut s = n.to_string();
// array lengths are obviously usize
if s.ends_with("_usize") {
let n = s.len() - "_usize".len();
s.truncate(n);
if s.ends_with(": ") {
let n = s.len() - ": ".len();
s.truncate(n);
}
}
s
// array lengths are obviously usize
ty::ConstKind::Value(ty::ValTree::Leaf(scalar))
if *n.ty().kind() == ty::Uint(ty::UintTy::Usize) =>
{
scalar.to_string()
}
_ => n.to_string(),
}
}