Skip to content

Commit 32c8c5d

Browse files
committedMay 23, 2022
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.
2 parents 9e2f655 + 207f649 commit 32c8c5d

File tree

7 files changed

+38
-37
lines changed

7 files changed

+38
-37
lines changed
 

‎compiler/rustc_resolve/src/late.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl RibKind<'_> {
182182
/// stack. This may be, for example, a `let` statement (because it introduces variables), a macro,
183183
/// etc.
184184
///
185-
/// Different [rib kinds](enum.RibKind) are transparent for different names.
185+
/// Different [rib kinds](enum@RibKind) are transparent for different names.
186186
///
187187
/// The resolution keeps a separate stack of ribs as it traverses the AST for each namespace. When
188188
/// resolving, the name is looked up from inside out.

‎src/librustdoc/clean/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ fn build_module(
544544
segments: vec![clean::PathSegment {
545545
name: prim_ty.as_sym(),
546546
args: clean::GenericArgs::AngleBracketed {
547-
args: Vec::new(),
547+
args: Default::default(),
548548
bindings: ThinVec::new(),
549549
},
550550
}],

‎src/librustdoc/clean/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ fn projection_to_path_segment(ty: ty::ProjectionTy<'_>, cx: &mut DocContext<'_>)
420420
PathSegment {
421421
name: item.name,
422422
args: GenericArgs::AngleBracketed {
423-
args: substs_to_args(cx, &ty.substs[generics.parent_count..], false),
423+
args: substs_to_args(cx, &ty.substs[generics.parent_count..], false).into(),
424424
bindings: Default::default(),
425425
},
426426
}
@@ -1205,7 +1205,7 @@ impl Clean<Item> for ty::AssocItem {
12051205
|| generics
12061206
.params
12071207
.iter()
1208-
.zip(args)
1208+
.zip(args.iter())
12091209
.any(|(param, arg)| !param_eq_arg(param, arg))
12101210
{
12111211
return false;
@@ -1837,7 +1837,7 @@ impl Clean<GenericArgs> for hir::GenericArgs<'_> {
18371837
let output = self.bindings[0].ty().clean(cx);
18381838
let output =
18391839
if output != Type::Tuple(Vec::new()) { Some(Box::new(output)) } else { None };
1840-
let inputs = self.inputs().iter().map(|x| x.clean(cx)).collect();
1840+
let inputs = self.inputs().iter().map(|x| x.clean(cx)).collect::<Vec<_>>().into();
18411841
GenericArgs::Parenthesized { inputs, output }
18421842
} else {
18431843
let args = self
@@ -1852,8 +1852,9 @@ impl Clean<GenericArgs> for hir::GenericArgs<'_> {
18521852
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(ct.clean(cx))),
18531853
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
18541854
})
1855-
.collect();
1856-
let bindings = self.bindings.iter().map(|x| x.clean(cx)).collect();
1855+
.collect::<Vec<_>>()
1856+
.into();
1857+
let bindings = self.bindings.iter().map(|x| x.clean(cx)).collect::<Vec<_>>().into();
18571858
GenericArgs::AngleBracketed { args, bindings }
18581859
}
18591860
}

‎src/librustdoc/clean/types.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ pub(crate) struct DocFragment {
994994
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
995995
rustc_data_structures::static_assert_size!(DocFragment, 32);
996996

997-
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
997+
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
998998
pub(crate) enum DocFragmentKind {
999999
/// A doc fragment created from a `///` or `//!` doc comment.
10001000
SugaredDoc,
@@ -2182,14 +2182,14 @@ rustc_data_structures::static_assert_size!(GenericArg, 80);
21822182

21832183
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
21842184
pub(crate) enum GenericArgs {
2185-
AngleBracketed { args: Vec<GenericArg>, bindings: ThinVec<TypeBinding> },
2186-
Parenthesized { inputs: Vec<Type>, output: Option<Box<Type>> },
2185+
AngleBracketed { args: Box<[GenericArg]>, bindings: ThinVec<TypeBinding> },
2186+
Parenthesized { inputs: Box<[Type]>, output: Option<Box<Type>> },
21872187
}
21882188

21892189
// `GenericArgs` is in every `PathSegment`, so its size can significantly
21902190
// affect rustdoc's memory usage.
21912191
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
2192-
rustc_data_structures::static_assert_size!(GenericArgs, 40);
2192+
rustc_data_structures::static_assert_size!(GenericArgs, 32);
21932193

21942194
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
21952195
pub(crate) struct PathSegment {
@@ -2200,7 +2200,7 @@ pub(crate) struct PathSegment {
22002200
// `PathSegment` usually occurs multiple times in every `Path`, so its size can
22012201
// significantly affect rustdoc's memory usage.
22022202
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
2203-
rustc_data_structures::static_assert_size!(PathSegment, 48);
2203+
rustc_data_structures::static_assert_size!(PathSegment, 40);
22042204

22052205
#[derive(Clone, Debug)]
22062206
pub(crate) struct Typedef {

‎src/librustdoc/clean/utils.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,23 @@ pub(crate) fn substs_to_args(
8080
substs: &[ty::subst::GenericArg<'_>],
8181
mut skip_first: bool,
8282
) -> Vec<GenericArg> {
83-
substs
84-
.iter()
85-
.filter_map(|kind| match kind.unpack() {
86-
GenericArgKind::Lifetime(lt) => match *lt {
87-
ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrAnon(_), .. }) => {
88-
Some(GenericArg::Lifetime(Lifetime::elided()))
89-
}
90-
_ => lt.clean(cx).map(GenericArg::Lifetime),
91-
},
92-
GenericArgKind::Type(_) if skip_first => {
93-
skip_first = false;
94-
None
83+
let mut ret_val =
84+
Vec::with_capacity(substs.len().saturating_sub(if skip_first { 1 } else { 0 }));
85+
ret_val.extend(substs.iter().filter_map(|kind| match kind.unpack() {
86+
GenericArgKind::Lifetime(lt) => match *lt {
87+
ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrAnon(_), .. }) => {
88+
Some(GenericArg::Lifetime(Lifetime::elided()))
9589
}
96-
GenericArgKind::Type(ty) => Some(GenericArg::Type(ty.clean(cx))),
97-
GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
98-
})
99-
.collect()
90+
_ => lt.clean(cx).map(GenericArg::Lifetime),
91+
},
92+
GenericArgKind::Type(_) if skip_first => {
93+
skip_first = false;
94+
None
95+
}
96+
GenericArgKind::Type(ty) => Some(GenericArg::Type(ty.clean(cx))),
97+
GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
98+
}));
99+
ret_val
100100
}
101101

102102
fn external_generic_args(
@@ -112,8 +112,8 @@ fn external_generic_args(
112112
let inputs =
113113
// The trait's first substitution is the one after self, if there is one.
114114
match substs.iter().nth(if has_self { 1 } else { 0 }).unwrap().expect_ty().kind() {
115-
ty::Tuple(tys) => tys.iter().map(|t| t.clean(cx)).collect(),
116-
_ => return GenericArgs::AngleBracketed { args, bindings: bindings.into() },
115+
ty::Tuple(tys) => tys.iter().map(|t| t.clean(cx)).collect::<Vec<_>>().into(),
116+
_ => return GenericArgs::AngleBracketed { args: args.into(), bindings: bindings.into() },
117117
};
118118
let output = None;
119119
// FIXME(#20299) return type comes from a projection now
@@ -123,7 +123,7 @@ fn external_generic_args(
123123
// };
124124
GenericArgs::Parenthesized { inputs, output }
125125
} else {
126-
GenericArgs::AngleBracketed { args, bindings: bindings.into() }
126+
GenericArgs::AngleBracketed { args: args.into(), bindings: bindings.into() }
127127
}
128128
}
129129

@@ -148,7 +148,7 @@ pub(super) fn external_path(
148148
/// Remove the generic arguments from a path.
149149
pub(crate) fn strip_path_generics(mut path: Path) -> Path {
150150
for ps in path.segments.iter_mut() {
151-
ps.args = GenericArgs::AngleBracketed { args: vec![], bindings: ThinVec::new() }
151+
ps.args = GenericArgs::AngleBracketed { args: Default::default(), bindings: ThinVec::new() }
152152
}
153153

154154
path

‎src/librustdoc/html/format.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ impl clean::GenericArgs {
457457
f.write_str("&lt;")?;
458458
}
459459
let mut comma = false;
460-
for arg in args {
460+
for arg in args.iter() {
461461
if comma {
462462
f.write_str(", ")?;
463463
}
@@ -468,7 +468,7 @@ impl clean::GenericArgs {
468468
write!(f, "{}", arg.print(cx))?;
469469
}
470470
}
471-
for binding in bindings {
471+
for binding in bindings.iter() {
472472
if comma {
473473
f.write_str(", ")?;
474474
}
@@ -489,7 +489,7 @@ impl clean::GenericArgs {
489489
clean::GenericArgs::Parenthesized { inputs, output } => {
490490
f.write_str("(")?;
491491
let mut comma = false;
492-
for ty in inputs {
492+
for ty in inputs.iter() {
493493
if comma {
494494
f.write_str(", ")?;
495495
}

‎src/librustdoc/json/conversions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ impl FromWithTcx<clean::GenericArgs> for GenericArgs {
119119
use clean::GenericArgs::*;
120120
match args {
121121
AngleBracketed { args, bindings } => GenericArgs::AngleBracketed {
122-
args: args.into_iter().map(|a| a.into_tcx(tcx)).collect(),
122+
args: args.into_vec().into_iter().map(|a| a.into_tcx(tcx)).collect(),
123123
bindings: bindings.into_iter().map(|a| a.into_tcx(tcx)).collect(),
124124
},
125125
Parenthesized { inputs, output } => GenericArgs::Parenthesized {
126-
inputs: inputs.into_iter().map(|a| a.into_tcx(tcx)).collect(),
126+
inputs: inputs.into_vec().into_iter().map(|a| a.into_tcx(tcx)).collect(),
127127
output: output.map(|a| (*a).into_tcx(tcx)),
128128
},
129129
}

0 commit comments

Comments
 (0)
Please sign in to comment.