Skip to content

Commit 85f8ae8

Browse files
committed
rustdoc: Remove Crate.src and instead compute it on-demand
It is only used in one place; `src` was about a third of `Crate`'s total size; `Crate` is frequently moved by-value; and `src` can be easily computed on-demand.
1 parent 47b0059 commit 85f8ae8

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/librustdoc/clean/types.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ impl From<DefId> for ItemId {
117117
#[derive(Clone, Debug)]
118118
crate struct Crate {
119119
crate name: Symbol,
120-
crate src: FileName,
121120
crate module: Item,
122121
crate externs: Vec<ExternalCrate>,
123122
crate primitives: ThinVec<(DefId, PrimitiveType)>,
@@ -128,7 +127,13 @@ crate struct Crate {
128127

129128
// `Crate` is frequently moved by-value. Make sure it doesn't unintentionally get bigger.
130129
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
131-
rustc_data_structures::static_assert_size!(Crate, 168);
130+
rustc_data_structures::static_assert_size!(Crate, 104);
131+
132+
impl Crate {
133+
crate fn src(&self, tcx: TyCtxt<'_>) -> FileName {
134+
ExternalCrate::LOCAL.src(tcx)
135+
}
136+
}
132137

133138
/// This struct is used to wrap additional information added by rustdoc on a `trait` item.
134139
#[derive(Clone, Debug)]

src/librustdoc/clean/utils.rs

-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
5757
}
5858

5959
let local_crate = ExternalCrate { crate_num: LOCAL_CRATE };
60-
let src = local_crate.src(cx.tcx);
6160
let name = local_crate.name(cx.tcx);
6261
let primitives = local_crate.primitives(cx.tcx);
6362
let keywords = local_crate.keywords(cx.tcx);
@@ -81,7 +80,6 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
8180

8281
Crate {
8382
name,
84-
src,
8583
module,
8684
externs,
8785
primitives,

src/librustdoc/html/render/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
405405
..
406406
} = options;
407407

408-
let src_root = match krate.src {
408+
let src_root = match krate.src(tcx) {
409409
FileName::Real(ref p) => match p.local_path_if_available().parent() {
410410
Some(p) => p.to_path_buf(),
411411
None => PathBuf::new(),

0 commit comments

Comments
 (0)