Skip to content

Commit e8831c8

Browse files
authored
Unrolled build for #150172
Rollup merge of #150172 - Urgau:rustdoc-remap-fixes, r=GuillaumeGomez Handle remapped paths correctly when generating "Source" links Fixes #150100. This PR fixes a regression introduced by [#149709](#149709), I was overzealous in my changes (https://github.com/rust-lang/rust/pull/149709/changes#diff-e1cf7ef2fb411d24980cd4cbea1e867cc36029e9496e1ceca64cfb6a0e3510f6) and accidentally changed the behavior of `rustdoc` in the presence of remapped, to simply reject them instead of handling them. With this PR remapped paths are handled correctly, in a similar way as it was before. ~~I added a run-make test to make sure we don't regress it again, a simple `rustdoc` test in not sufficient as `rustdoc` is not called on the auxiliary crate. It's not pretty but it works.~~ #150172 (comment) rustdoc doesn't have any handling for `--remap-path-scope`, so I used the `MACRO` scope (it was already used [elsewhere](https://github.com/rust-lang/rust/blob/b889870082dd0b0e3594bbfbebb4545d54710829/src/librustdoc/clean/types.rs#L154). cf. https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/source.20links.20missing.20for.20nightly.20std.20docs
2 parents d0835ad + c039edd commit e8831c8

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
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
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ compile-flags:-Zunstable-options --remap-path-prefix={{src-base}}=
2+
3+
pub struct MyStruct {
4+
field: u32,
5+
}
6+
7+
impl MyStruct {
8+
pub fn new() -> MyStruct {
9+
MyStruct { field: 3 }
10+
}
11+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This is a regression for `--remap-path-prefix` in an auxiliary dependency.
2+
//
3+
// We want to make sure that we can still have the "Source" links to the dependency
4+
// even if its paths are remapped.
5+
//
6+
// See also rust-lang/rust#150100
7+
8+
//@ aux-build:remapped-paths.rs
9+
//@ build-aux-docs
10+
11+
#![crate_name = "foo"]
12+
13+
extern crate remapped_paths;
14+
15+
//@ has foo/struct.MyStruct.html
16+
//@ has - '//a[@href="../src/remapped_paths/remapped-paths.rs.html#3"]' 'Source'
17+
//@ has - '//a[@href="../src/remapped_paths/remapped-paths.rs.html#8"]' 'Source'
18+
19+
pub use remapped_paths::MyStruct;

0 commit comments

Comments
 (0)