Use local and remapped paths where appropriate

This commit is contained in:
Andy Wang 2021-04-19 23:27:02 +01:00
parent fb4f6439f6
commit 5417b45c26
No known key found for this signature in database
GPG key ID: 181B49F9F38F3374
28 changed files with 85 additions and 74 deletions

View file

@ -376,17 +376,10 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
} = options;
let src_root = match krate.src {
FileName::Real(ref p) => {
if let Some(local_path) = p.local_path() {
match local_path.parent() {
Some(p) => p.to_path_buf(),
None => PathBuf::new(),
}
} else {
// Somehow we got the filename from the metadata of another crate, should never happen
PathBuf::new()
}
}
FileName::Real(ref p) => match p.local_path_if_available().parent() {
Some(p) => p.to_path_buf(),
None => PathBuf::new(),
},
_ => PathBuf::new(),
};
// If user passed in `--playground-url` arg, we fill in crate name here

View file

@ -56,7 +56,11 @@ impl DocFolder for SourceCollector<'_, '_> {
Err(e) => {
self.scx.tcx.sess.span_err(
item.span(self.scx.tcx).inner(),
&format!("failed to render source code for `{}`: {}", filename, e),
&format!(
"failed to render source code for `{}`: {}",
filename.prefer_local(),
e
),
);
false
}
@ -80,7 +84,7 @@ impl SourceCollector<'_, 'tcx> {
if let Some(local_path) = file.local_path() {
local_path.to_path_buf()
} else {
return Ok(());
unreachable!("only the current crate should have sources emitted");
}
}
_ => return Ok(()),
@ -119,7 +123,7 @@ impl SourceCollector<'_, 'tcx> {
href.push_str(&fname.to_string_lossy());
let title = format!("{} - source", src_fname.to_string_lossy());
let desc = format!("Source of the Rust file `{}`.", filename);
let desc = format!("Source of the Rust file `{}`.", filename.prefer_remapped());
let page = layout::Page {
title: &title,
css_class: "source",