Skip to content

Commit 811c241

Browse files
committed
Handle remapped paths correctly when generating "Source" links
1 parent 81d86bf commit 811c241

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/librustdoc/html/render/context.rs

Lines changed: 11 additions & 6 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,10 @@ 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
369+
.local_path()
370+
.unwrap_or(path.path(RemapPathScopeComponents::MACRO))
371+
.to_path_buf(),
369372
_ => return None,
370373
};
371374
let file = &file;
@@ -499,10 +502,12 @@ impl<'tcx> Context<'tcx> {
499502
} = options;
500503

501504
let src_root = match krate.src(tcx) {
502-
FileName::Real(ref p) => match p.local_path().map(|p| p.parent()).flatten() {
503-
Some(p) => p.to_path_buf(),
504-
None => PathBuf::new(),
505-
},
505+
FileName::Real(ref p) => {
506+
match p.local_path().unwrap_or(p.path(RemapPathScopeComponents::MACRO)).parent() {
507+
Some(p) => p.to_path_buf(),
508+
None => PathBuf::new(),
509+
}
510+
}
506511
_ => PathBuf::new(),
507512
};
508513
// If user passed in `--playground-url` arg, we fill in crate name here

tests/rustdoc/import-remapped-paths.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
extern crate remapped_paths;
1414

1515
//@ has foo/struct.MyStruct.html
16-
// FIXME: Doesn't work!
1716
//@ has - '//a[@href="../src/remapped_paths/remapped-paths.rs.html#3"]' 'Source'
1817
//@ has - '//a[@href="../src/remapped_paths/remapped-paths.rs.html#8"]' 'Source'
1918

0 commit comments

Comments
 (0)