diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/clean/types.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/doctest.rs | 22 | ||||
| -rw-r--r-- | src/librustdoc/html/render/context.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/html/sources.rs | 16 | ||||
| -rw-r--r-- | src/librustdoc/json/conversions.rs | 23 | ||||
| -rw-r--r-- | src/librustdoc/passes/calculate_doc_coverage.rs | 6 | ||||
| -rw-r--r-- | src/test/codegen/remap_path_prefix/issue-73167-remap-std.rs | 15 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/macro_use.rs | 9 | ||||
| -rw-r--r-- | src/tools/compiletest/src/runtest.rs | 6 |
9 files changed, 70 insertions, 33 deletions
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index bca7a8cfcee..7d802636bfa 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -164,7 +164,7 @@ impl ExternalCrate { crate fn src_root(&self, tcx: TyCtxt<'_>) -> PathBuf { match self.src(tcx) { - FileName::Real(ref p) => match p.local_path().parent() { + FileName::Real(ref p) => match p.local_path_if_available().parent() { Some(p) => p.to_path_buf(), None => PathBuf::new(), }, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 03e3fe52f71..3a4d39e1d7f 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -839,7 +839,7 @@ impl Collector { if !item_path.is_empty() { item_path.push(' '); } - format!("{} - {}(line {})", filename, item_path, line) + format!("{} - {}(line {})", filename.prefer_local(), item_path, line) } crate fn set_position(&mut self, position: Span) { @@ -851,8 +851,10 @@ impl Collector { let filename = source_map.span_to_filename(self.position); if let FileName::Real(ref filename) = filename { if let Ok(cur_dir) = env::current_dir() { - if let Ok(path) = filename.local_path().strip_prefix(&cur_dir) { - return path.to_owned().into(); + if let Some(local_path) = filename.local_path() { + if let Ok(path) = local_path.strip_prefix(&cur_dir) { + return path.to_owned().into(); + } } } } @@ -882,16 +884,22 @@ impl Tester for Collector { self.compiling_test_count.fetch_add(1, Ordering::SeqCst); } - // FIXME(#44940): if doctests ever support path remapping, then this filename - // needs to be the result of `SourceMap::span_to_unmapped_path`. let path = match &filename { - FileName::Real(path) => path.local_path().to_path_buf(), + FileName::Real(path) => { + if let Some(local_path) = path.local_path() { + local_path.to_path_buf() + } else { + // Somehow we got the filename from the metadata of another crate, should never happen + unreachable!("doctest from a different crate"); + } + } _ => PathBuf::from(r"doctest.rs"), }; // For example `module/file.rs` would become `module_file_rs` let file = filename - .to_string() + .prefer_local() + .to_string_lossy() .chars() .map(|c| if c.is_ascii_alphanumeric() { c } else { '_' }) .collect::<String>(); diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 666d9dfc3e9..8fd5d8b6b85 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -293,7 +293,7 @@ impl<'tcx> Context<'tcx> { // We can safely ignore synthetic `SourceFile`s. let file = match item.span(self.tcx()).filename(self.sess()) { - FileName::Real(ref path) => path.local_path().to_path_buf(), + FileName::Real(ref path) => path.local_path_if_available().to_path_buf(), _ => return None, }; let file = &file; @@ -380,7 +380,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { } = options; let src_root = match krate.src { - FileName::Real(ref p) => match p.local_path().parent() { + FileName::Real(ref p) => match p.local_path_if_available().parent() { Some(p) => p.to_path_buf(), None => PathBuf::new(), }, diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index 57c33f94918..5e2a94fe684 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -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 } @@ -76,7 +80,13 @@ impl SourceCollector<'_, 'tcx> { /// Renders the given filename into its corresponding HTML source file. fn emit_source(&mut self, filename: &FileName) -> Result<(), Error> { let p = match *filename { - FileName::Real(ref file) => file.local_path().to_path_buf(), + FileName::Real(ref file) => { + if let Some(local_path) = file.local_path() { + local_path.to_path_buf() + } else { + unreachable!("only the current crate should have sources emitted"); + } + } _ => return Ok(()), }; if self.scx.local_sources.contains_key(&*p) { @@ -113,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", diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index e3f1c6b1e2d..e0e5db3b563 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -64,18 +64,17 @@ impl JsonRenderer<'_> { fn convert_span(&self, span: clean::Span) -> Option<Span> { match span.filename(self.sess()) { rustc_span::FileName::Real(name) => { - let hi = span.hi(self.sess()); - let lo = span.lo(self.sess()); - Some(Span { - filename: match name { - rustc_span::RealFileName::Named(path) => path, - rustc_span::RealFileName::Devirtualized { local_path, virtual_name: _ } => { - local_path - } - }, - begin: (lo.line, lo.col.to_usize()), - end: (hi.line, hi.col.to_usize()), - }) + if let Some(local_path) = name.into_local_path() { + let hi = span.hi(self.sess()); + let lo = span.lo(self.sess()); + Some(Span { + filename: local_path, + begin: (lo.line, lo.col.to_usize()), + end: (hi.line, hi.col.to_usize()), + }) + } else { + None + } } _ => None, } diff --git a/src/librustdoc/passes/calculate_doc_coverage.rs b/src/librustdoc/passes/calculate_doc_coverage.rs index e65fcf057f1..26a22f5b304 100644 --- a/src/librustdoc/passes/calculate_doc_coverage.rs +++ b/src/librustdoc/passes/calculate_doc_coverage.rs @@ -119,7 +119,7 @@ impl<'a, 'b> CoverageCalculator<'a, 'b> { &self .items .iter() - .map(|(k, v)| (k.to_string(), v)) + .map(|(k, v)| (k.prefer_local().to_string(), v)) .collect::<BTreeMap<String, &ItemCount>>(), ) .expect("failed to convert JSON data to string") @@ -159,7 +159,7 @@ impl<'a, 'b> CoverageCalculator<'a, 'b> { for (file, &count) in &self.items { if let Some(percentage) = count.percentage() { print_table_record( - &limit_filename_len(file.to_string()), + &limit_filename_len(file.prefer_local().to_string_lossy().into()), count, percentage, count.examples_percentage().unwrap_or(0.), @@ -225,7 +225,7 @@ impl<'a, 'b> fold::DocFolder for CoverageCalculator<'a, 'b> { // unless the user had an explicit `allow` let should_have_docs = level != lint::Level::Allow || matches!(source, LintLevelSource::Default); - debug!("counting {:?} {:?} in {}", i.type_(), i.name, filename); + debug!("counting {:?} {:?} in {:?}", i.type_(), i.name, filename); self.items.entry(filename).or_default().count_item( has_docs, has_doc_example, diff --git a/src/test/codegen/remap_path_prefix/issue-73167-remap-std.rs b/src/test/codegen/remap_path_prefix/issue-73167-remap-std.rs new file mode 100644 index 00000000000..b66abc6bedf --- /dev/null +++ b/src/test/codegen/remap_path_prefix/issue-73167-remap-std.rs @@ -0,0 +1,15 @@ +// ignore-windows + +// compile-flags: -g -C no-prepopulate-passes -Z simulate-remapped-rust-src-base=/rustc/xyz + +// Here we check that importing std will not cause real path to std source files +// to leak. If rustc was compiled with remap-debuginfo = true, this should be +// true automatically. If paths to std library hasn't been remapped, we use the +// above simulate-remapped-rust-src-base option to do it temporarily + +// CHECK: !DIFile(filename: "{{/rustc/.*/library/std/src/panic.rs}}" +fn main() { + std::thread::spawn(|| { + println!("hello"); + }); +} diff --git a/src/tools/clippy/clippy_lints/src/macro_use.rs b/src/tools/clippy/clippy_lints/src/macro_use.rs index ec03daff87b..314bf11e2d6 100644 --- a/src/tools/clippy/clippy_lints/src/macro_use.rs +++ b/src/tools/clippy/clippy_lints/src/macro_use.rs @@ -47,7 +47,7 @@ pub struct MacroRefData { impl MacroRefData { pub fn new(name: String, callee: Span, cx: &LateContext<'_>) -> Self { - let mut path = cx.sess().source_map().span_to_filename(callee).to_string(); + let mut path = cx.sess().source_map().span_to_filename(callee).prefer_local().to_string(); // std lib paths are <::std::module::file type> // so remove brackets, space and type. @@ -96,8 +96,7 @@ impl MacroUseImports { let name = snippet(cx, cx.sess().source_map().span_until_char(call_site, '!'), "_"); if let Some(callee) = span.source_callee() { if !self.collected.contains(&call_site) { - self.mac_refs - .push(MacroRefData::new(name.to_string(), callee.def_site, cx)); + self.mac_refs.push(MacroRefData::new(name.to_string(), callee.def_site, cx)); self.collected.insert(call_site); } } @@ -175,7 +174,7 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports { .push((*item).to_string()); check_dup.push((*item).to_string()); } - }, + } [root, rest @ ..] => { if rest.iter().all(|item| !check_dup.contains(&(*item).to_string())) { let filtered = rest @@ -199,7 +198,7 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports { .push(rest.join("::")); check_dup.extend(rest.iter().map(ToString::to_string)); } - }, + } } } } diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index c606aa1dfbf..f4e16483d8c 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -3650,6 +3650,12 @@ impl<'test> TestCx<'test> { .join("library"); normalize_path(&src_dir, "$SRC_DIR"); + if let Some(virtual_rust_source_base_dir) = + option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").map(PathBuf::from) + { + normalize_path(&virtual_rust_source_base_dir.join("library"), "$SRC_DIR"); + } + // Paths into the build directory let test_build_dir = &self.config.build_base; let parent_build_dir = test_build_dir.parent().unwrap().parent().unwrap().parent().unwrap(); |
