Skip to content

Commit dfdb113

Browse files
committed
Handle remapped paths correctly when generating "Source" links
1 parent 8564496 commit dfdb113

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/librustdoc/html/render/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_hir::def_id::{DefIdMap, LOCAL_CRATE};
1414
use rustc_middle::ty::TyCtxt;
1515
use rustc_session::Session;
1616
use rustc_span::edition::Edition;
17-
use rustc_span::{BytePos, FileName, Symbol};
17+
use rustc_span::{BytePos, FileName, RemapPathScopeComponents, Symbol};
1818
use tracing::info;
1919

2020
use super::print_item::{full_path, print_item, print_item_path};
@@ -365,7 +365,7 @@ impl<'tcx> Context<'tcx> {
365365

366366
// We can safely ignore synthetic `SourceFile`s.
367367
let file = match span.filename(self.sess()) {
368-
FileName::Real(ref path) => path.local_path()?.to_path_buf(),
368+
FileName::Real(ref path) => path.path(RemapPathScopeComponents::MACRO).to_path_buf(),
369369
_ => return None,
370370
};
371371
let file = &file;
@@ -499,7 +499,7 @@ impl<'tcx> Context<'tcx> {
499499
} = options;
500500

501501
let src_root = match krate.src(tcx) {
502-
FileName::Real(ref p) => match p.local_path().map(|p| p.parent()).flatten() {
502+
FileName::Real(ref p) => match p.path(RemapPathScopeComponents::MACRO).parent() {
503503
Some(p) => p.to_path_buf(),
504504
None => PathBuf::new(),
505505
},

tests/run-make/rustdoc-remapped-paths/rmake.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ fn main() {
1818

1919
// Let's verify that "Source" links for dep exist in `MyStruct` page
2020
let reexport_MyStruct_content = rfs::read_to_string("doc/reexport/struct.MyStruct.html");
21-
// FIXME: Those assert don't work!
2221
assert!(reexport_MyStruct_content.contains(r#""../src/dep/dep.rs.html#1">Source"#));
2322
assert!(reexport_MyStruct_content.contains(r#""../src/dep/dep.rs.html#6">Source"#));
2423
}

0 commit comments

Comments
 (0)