Auto merge of #97195 - notriddle:notriddle/cleanup, r=GuillaumeGomez
rustdoc: shrink GenericArgs/PathSegment with boxed slices This PR also contains a few cleanup bits and pieces, but one of them is a broken intra-doc link, and the other is removing an unused Hash impl. The last commit is the one that matters.
This commit is contained in:
commit
32c8c5df06
7 changed files with 38 additions and 37 deletions
|
@ -182,7 +182,7 @@ impl RibKind<'_> {
|
||||||
/// stack. This may be, for example, a `let` statement (because it introduces variables), a macro,
|
/// stack. This may be, for example, a `let` statement (because it introduces variables), a macro,
|
||||||
/// etc.
|
/// etc.
|
||||||
///
|
///
|
||||||
/// Different [rib kinds](enum.RibKind) are transparent for different names.
|
/// Different [rib kinds](enum@RibKind) are transparent for different names.
|
||||||
///
|
///
|
||||||
/// The resolution keeps a separate stack of ribs as it traverses the AST for each namespace. When
|
/// The resolution keeps a separate stack of ribs as it traverses the AST for each namespace. When
|
||||||
/// resolving, the name is looked up from inside out.
|
/// resolving, the name is looked up from inside out.
|
||||||
|
|
|
@ -544,7 +544,7 @@ fn build_module(
|
||||||
segments: vec![clean::PathSegment {
|
segments: vec![clean::PathSegment {
|
||||||
name: prim_ty.as_sym(),
|
name: prim_ty.as_sym(),
|
||||||
args: clean::GenericArgs::AngleBracketed {
|
args: clean::GenericArgs::AngleBracketed {
|
||||||
args: Vec::new(),
|
args: Default::default(),
|
||||||
bindings: ThinVec::new(),
|
bindings: ThinVec::new(),
|
||||||
},
|
},
|
||||||
}],
|
}],
|
||||||
|
|
|
@ -420,7 +420,7 @@ fn projection_to_path_segment(ty: ty::ProjectionTy<'_>, cx: &mut DocContext<'_>)
|
||||||
PathSegment {
|
PathSegment {
|
||||||
name: item.name,
|
name: item.name,
|
||||||
args: GenericArgs::AngleBracketed {
|
args: GenericArgs::AngleBracketed {
|
||||||
args: substs_to_args(cx, &ty.substs[generics.parent_count..], false),
|
args: substs_to_args(cx, &ty.substs[generics.parent_count..], false).into(),
|
||||||
bindings: Default::default(),
|
bindings: Default::default(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1205,7 +1205,7 @@ impl Clean<Item> for ty::AssocItem {
|
||||||
|| generics
|
|| generics
|
||||||
.params
|
.params
|
||||||
.iter()
|
.iter()
|
||||||
.zip(args)
|
.zip(args.iter())
|
||||||
.any(|(param, arg)| !param_eq_arg(param, arg))
|
.any(|(param, arg)| !param_eq_arg(param, arg))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -1837,7 +1837,7 @@ impl Clean<GenericArgs> for hir::GenericArgs<'_> {
|
||||||
let output = self.bindings[0].ty().clean(cx);
|
let output = self.bindings[0].ty().clean(cx);
|
||||||
let output =
|
let output =
|
||||||
if output != Type::Tuple(Vec::new()) { Some(Box::new(output)) } else { None };
|
if output != Type::Tuple(Vec::new()) { Some(Box::new(output)) } else { None };
|
||||||
let inputs = self.inputs().iter().map(|x| x.clean(cx)).collect();
|
let inputs = self.inputs().iter().map(|x| x.clean(cx)).collect::<Vec<_>>().into();
|
||||||
GenericArgs::Parenthesized { inputs, output }
|
GenericArgs::Parenthesized { inputs, output }
|
||||||
} else {
|
} else {
|
||||||
let args = self
|
let args = self
|
||||||
|
@ -1852,8 +1852,9 @@ impl Clean<GenericArgs> for hir::GenericArgs<'_> {
|
||||||
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(ct.clean(cx))),
|
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(ct.clean(cx))),
|
||||||
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
|
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
|
||||||
})
|
})
|
||||||
.collect();
|
.collect::<Vec<_>>()
|
||||||
let bindings = self.bindings.iter().map(|x| x.clean(cx)).collect();
|
.into();
|
||||||
|
let bindings = self.bindings.iter().map(|x| x.clean(cx)).collect::<Vec<_>>().into();
|
||||||
GenericArgs::AngleBracketed { args, bindings }
|
GenericArgs::AngleBracketed { args, bindings }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -994,7 +994,7 @@ pub(crate) struct DocFragment {
|
||||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||||
rustc_data_structures::static_assert_size!(DocFragment, 32);
|
rustc_data_structures::static_assert_size!(DocFragment, 32);
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
pub(crate) enum DocFragmentKind {
|
pub(crate) enum DocFragmentKind {
|
||||||
/// A doc fragment created from a `///` or `//!` doc comment.
|
/// A doc fragment created from a `///` or `//!` doc comment.
|
||||||
SugaredDoc,
|
SugaredDoc,
|
||||||
|
@ -2182,14 +2182,14 @@ rustc_data_structures::static_assert_size!(GenericArg, 80);
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||||
pub(crate) enum GenericArgs {
|
pub(crate) enum GenericArgs {
|
||||||
AngleBracketed { args: Vec<GenericArg>, bindings: ThinVec<TypeBinding> },
|
AngleBracketed { args: Box<[GenericArg]>, bindings: ThinVec<TypeBinding> },
|
||||||
Parenthesized { inputs: Vec<Type>, output: Option<Box<Type>> },
|
Parenthesized { inputs: Box<[Type]>, output: Option<Box<Type>> },
|
||||||
}
|
}
|
||||||
|
|
||||||
// `GenericArgs` is in every `PathSegment`, so its size can significantly
|
// `GenericArgs` is in every `PathSegment`, so its size can significantly
|
||||||
// affect rustdoc's memory usage.
|
// affect rustdoc's memory usage.
|
||||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||||
rustc_data_structures::static_assert_size!(GenericArgs, 40);
|
rustc_data_structures::static_assert_size!(GenericArgs, 32);
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||||
pub(crate) struct PathSegment {
|
pub(crate) struct PathSegment {
|
||||||
|
@ -2200,7 +2200,7 @@ pub(crate) struct PathSegment {
|
||||||
// `PathSegment` usually occurs multiple times in every `Path`, so its size can
|
// `PathSegment` usually occurs multiple times in every `Path`, so its size can
|
||||||
// significantly affect rustdoc's memory usage.
|
// significantly affect rustdoc's memory usage.
|
||||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||||
rustc_data_structures::static_assert_size!(PathSegment, 48);
|
rustc_data_structures::static_assert_size!(PathSegment, 40);
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct Typedef {
|
pub(crate) struct Typedef {
|
||||||
|
|
|
@ -80,23 +80,23 @@ pub(crate) fn substs_to_args(
|
||||||
substs: &[ty::subst::GenericArg<'_>],
|
substs: &[ty::subst::GenericArg<'_>],
|
||||||
mut skip_first: bool,
|
mut skip_first: bool,
|
||||||
) -> Vec<GenericArg> {
|
) -> Vec<GenericArg> {
|
||||||
substs
|
let mut ret_val =
|
||||||
.iter()
|
Vec::with_capacity(substs.len().saturating_sub(if skip_first { 1 } else { 0 }));
|
||||||
.filter_map(|kind| match kind.unpack() {
|
ret_val.extend(substs.iter().filter_map(|kind| match kind.unpack() {
|
||||||
GenericArgKind::Lifetime(lt) => match *lt {
|
GenericArgKind::Lifetime(lt) => match *lt {
|
||||||
ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrAnon(_), .. }) => {
|
ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrAnon(_), .. }) => {
|
||||||
Some(GenericArg::Lifetime(Lifetime::elided()))
|
Some(GenericArg::Lifetime(Lifetime::elided()))
|
||||||
}
|
|
||||||
_ => lt.clean(cx).map(GenericArg::Lifetime),
|
|
||||||
},
|
|
||||||
GenericArgKind::Type(_) if skip_first => {
|
|
||||||
skip_first = false;
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
GenericArgKind::Type(ty) => Some(GenericArg::Type(ty.clean(cx))),
|
_ => lt.clean(cx).map(GenericArg::Lifetime),
|
||||||
GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
|
},
|
||||||
})
|
GenericArgKind::Type(_) if skip_first => {
|
||||||
.collect()
|
skip_first = false;
|
||||||
|
None
|
||||||
|
}
|
||||||
|
GenericArgKind::Type(ty) => Some(GenericArg::Type(ty.clean(cx))),
|
||||||
|
GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
|
||||||
|
}));
|
||||||
|
ret_val
|
||||||
}
|
}
|
||||||
|
|
||||||
fn external_generic_args(
|
fn external_generic_args(
|
||||||
|
@ -112,8 +112,8 @@ fn external_generic_args(
|
||||||
let inputs =
|
let inputs =
|
||||||
// The trait's first substitution is the one after self, if there is one.
|
// The trait's first substitution is the one after self, if there is one.
|
||||||
match substs.iter().nth(if has_self { 1 } else { 0 }).unwrap().expect_ty().kind() {
|
match substs.iter().nth(if has_self { 1 } else { 0 }).unwrap().expect_ty().kind() {
|
||||||
ty::Tuple(tys) => tys.iter().map(|t| t.clean(cx)).collect(),
|
ty::Tuple(tys) => tys.iter().map(|t| t.clean(cx)).collect::<Vec<_>>().into(),
|
||||||
_ => return GenericArgs::AngleBracketed { args, bindings: bindings.into() },
|
_ => return GenericArgs::AngleBracketed { args: args.into(), bindings: bindings.into() },
|
||||||
};
|
};
|
||||||
let output = None;
|
let output = None;
|
||||||
// FIXME(#20299) return type comes from a projection now
|
// FIXME(#20299) return type comes from a projection now
|
||||||
|
@ -123,7 +123,7 @@ fn external_generic_args(
|
||||||
// };
|
// };
|
||||||
GenericArgs::Parenthesized { inputs, output }
|
GenericArgs::Parenthesized { inputs, output }
|
||||||
} else {
|
} else {
|
||||||
GenericArgs::AngleBracketed { args, bindings: bindings.into() }
|
GenericArgs::AngleBracketed { args: args.into(), bindings: bindings.into() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ pub(super) fn external_path(
|
||||||
/// Remove the generic arguments from a path.
|
/// Remove the generic arguments from a path.
|
||||||
pub(crate) fn strip_path_generics(mut path: Path) -> Path {
|
pub(crate) fn strip_path_generics(mut path: Path) -> Path {
|
||||||
for ps in path.segments.iter_mut() {
|
for ps in path.segments.iter_mut() {
|
||||||
ps.args = GenericArgs::AngleBracketed { args: vec![], bindings: ThinVec::new() }
|
ps.args = GenericArgs::AngleBracketed { args: Default::default(), bindings: ThinVec::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
path
|
path
|
||||||
|
|
|
@ -457,7 +457,7 @@ impl clean::GenericArgs {
|
||||||
f.write_str("<")?;
|
f.write_str("<")?;
|
||||||
}
|
}
|
||||||
let mut comma = false;
|
let mut comma = false;
|
||||||
for arg in args {
|
for arg in args.iter() {
|
||||||
if comma {
|
if comma {
|
||||||
f.write_str(", ")?;
|
f.write_str(", ")?;
|
||||||
}
|
}
|
||||||
|
@ -468,7 +468,7 @@ impl clean::GenericArgs {
|
||||||
write!(f, "{}", arg.print(cx))?;
|
write!(f, "{}", arg.print(cx))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for binding in bindings {
|
for binding in bindings.iter() {
|
||||||
if comma {
|
if comma {
|
||||||
f.write_str(", ")?;
|
f.write_str(", ")?;
|
||||||
}
|
}
|
||||||
|
@ -489,7 +489,7 @@ impl clean::GenericArgs {
|
||||||
clean::GenericArgs::Parenthesized { inputs, output } => {
|
clean::GenericArgs::Parenthesized { inputs, output } => {
|
||||||
f.write_str("(")?;
|
f.write_str("(")?;
|
||||||
let mut comma = false;
|
let mut comma = false;
|
||||||
for ty in inputs {
|
for ty in inputs.iter() {
|
||||||
if comma {
|
if comma {
|
||||||
f.write_str(", ")?;
|
f.write_str(", ")?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,11 +119,11 @@ impl FromWithTcx<clean::GenericArgs> for GenericArgs {
|
||||||
use clean::GenericArgs::*;
|
use clean::GenericArgs::*;
|
||||||
match args {
|
match args {
|
||||||
AngleBracketed { args, bindings } => GenericArgs::AngleBracketed {
|
AngleBracketed { args, bindings } => GenericArgs::AngleBracketed {
|
||||||
args: args.into_iter().map(|a| a.into_tcx(tcx)).collect(),
|
args: args.into_vec().into_iter().map(|a| a.into_tcx(tcx)).collect(),
|
||||||
bindings: bindings.into_iter().map(|a| a.into_tcx(tcx)).collect(),
|
bindings: bindings.into_iter().map(|a| a.into_tcx(tcx)).collect(),
|
||||||
},
|
},
|
||||||
Parenthesized { inputs, output } => GenericArgs::Parenthesized {
|
Parenthesized { inputs, output } => GenericArgs::Parenthesized {
|
||||||
inputs: inputs.into_iter().map(|a| a.into_tcx(tcx)).collect(),
|
inputs: inputs.into_vec().into_iter().map(|a| a.into_tcx(tcx)).collect(),
|
||||||
output: output.map(|a| (*a).into_tcx(tcx)),
|
output: output.map(|a| (*a).into_tcx(tcx)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue