Skip to content

Commit 5407a69

Browse files
committed
Remove src field from ExternCrate
1 parent 25c15cd commit 5407a69

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ impl Clean<ExternalCrate> for CrateNum {
8686
fn clean(&self, cx: &mut DocContext<'_>) -> ExternalCrate {
8787
let tcx = cx.tcx;
8888
let root = DefId { krate: *self, index: CRATE_DEF_INDEX };
89-
let krate_span = tcx.def_span(root);
90-
let krate_src = cx.sess().source_map().span_to_filename(krate_span);
9189

9290
// Collect all inner modules which are tagged as implementations of
9391
// primitives.
@@ -195,8 +193,8 @@ impl Clean<ExternalCrate> for CrateNum {
195193
};
196194

197195
ExternalCrate {
196+
crate_num: *self,
198197
name: tcx.crate_name(*self),
199-
src: krate_src,
200198
attrs: tcx.get_attrs(root).clean(cx),
201199
primitives,
202200
keywords,

src/librustdoc/clean/types.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,21 @@ crate struct TraitWithExtraInfo {
7272

7373
#[derive(Clone, Debug)]
7474
crate struct ExternalCrate {
75+
crate crate_num: CrateNum,
7576
crate name: Symbol,
76-
crate src: FileName,
7777
crate attrs: Attributes,
7878
crate primitives: ThinVec<(DefId, PrimitiveType)>,
7979
crate keywords: ThinVec<(DefId, Symbol)>,
8080
}
8181

82+
impl ExternalCrate {
83+
crate fn src(&self, tcx: TyCtxt<'_>) -> FileName {
84+
let root = DefId { krate: self.crate_num, index: rustc_hir::def_id::CRATE_DEF_INDEX };
85+
let krate_span = tcx.def_span(root);
86+
tcx.sess.source_map().span_to_filename(krate_span)
87+
}
88+
}
89+
8290
/// Anything with a source location and set of attributes and, optionally, a
8391
/// name. That is, anything that can be documented. This doesn't correspond
8492
/// directly to the AST's concept of an item; it's a strict superset.

src/librustdoc/clean/utils.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
5454
_ => unreachable!(),
5555
}
5656

57-
let ExternalCrate { name, src, primitives, keywords, .. } = LOCAL_CRATE.clean(cx);
57+
let local_crate = LOCAL_CRATE.clean(cx);
58+
let src = local_crate.src(cx.tcx);
59+
let ExternalCrate { name, primitives, keywords, .. } = local_crate;
5860
{
5961
let m = match *module.kind {
6062
ItemKind::ModuleItem(ref mut m) => m,

src/librustdoc/formats/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl Cache {
155155
// Cache where all our extern crates are located
156156
// FIXME: this part is specific to HTML so it'd be nice to remove it from the common code
157157
for &(n, ref e) in &krate.externs {
158-
let src_root = match e.src {
158+
let src_root = match e.src(tcx) {
159159
FileName::Real(ref p) => match p.local_path().parent() {
160160
Some(p) => p.to_path_buf(),
161161
None => PathBuf::new(),

0 commit comments

Comments
 (0)