Auto merge of #88363 - michaelwoerister:remapped-diagnostics, r=estebank
Path remapping: Make behavior of diagnostics output dependent on presence of --remap-path-prefix. This PR fixes a regression (#87745) with `--remap-path-prefix` where the flag stopped causing diagnostic messages to be remapped as well. The regression was introduced in https://github.com/rust-lang/rust/pull/83813 where we erroneously assumed that remapping of diagnostic messages was not desired anymore (because #70642 partially undid that functionality with nobody objecting). The issue is fixed by making `--remap-path-prefix` remap diagnostic messages again, including for paths that have been remapped in upstream crates (e.g. the standard library). This means that "sysroot-localization" (implemented in #70642) is also disabled if `rustc` is invoked with `--remap-path-prefix`. The assumption is that once someone starts explicitly remapping paths they also don't want paths to their local Rust installation in their build output. In the future we might want to give more fine-grained control over this behavior via compiler flags (see https://github.com/rust-lang/rfcs/pull/3127 for a related RFC). For now this PR is intended as a regression fix. This PR is an alternative to https://github.com/rust-lang/rust/pull/88191, which makes diagnostic messages be remapped unconditionally. That approach, however, would effectively revert #70642. Fixes https://github.com/rust-lang/rust/issues/87745. cc `@cbeuw` r? `@ghost`
This commit is contained in:
commit
97f2698484
15 changed files with 83 additions and 41 deletions
|
@ -427,7 +427,7 @@ impl SourceMap {
|
|||
}
|
||||
}
|
||||
|
||||
fn span_to_string(&self, sp: Span, prefer_local: bool) -> String {
|
||||
fn span_to_string(&self, sp: Span, filename_display_pref: FileNameDisplayPreference) -> String {
|
||||
if self.files.borrow().source_files.is_empty() || sp.is_dummy() {
|
||||
return "no-location".to_string();
|
||||
}
|
||||
|
@ -436,7 +436,7 @@ impl SourceMap {
|
|||
let hi = self.lookup_char_pos(sp.hi());
|
||||
format!(
|
||||
"{}:{}:{}: {}:{}",
|
||||
if prefer_local { lo.file.name.prefer_local() } else { lo.file.name.prefer_remapped() },
|
||||
lo.file.name.display(filename_display_pref),
|
||||
lo.line,
|
||||
lo.col.to_usize() + 1,
|
||||
hi.line,
|
||||
|
@ -446,20 +446,24 @@ impl SourceMap {
|
|||
|
||||
/// Format the span location suitable for embedding in build artifacts
|
||||
pub fn span_to_embeddable_string(&self, sp: Span) -> String {
|
||||
self.span_to_string(sp, false)
|
||||
self.span_to_string(sp, FileNameDisplayPreference::Remapped)
|
||||
}
|
||||
|
||||
/// Format the span location to be printed in diagnostics. Must not be emitted
|
||||
/// to build artifacts as this may leak local file paths. Use span_to_embeddable_string
|
||||
/// for string suitable for embedding.
|
||||
pub fn span_to_diagnostic_string(&self, sp: Span) -> String {
|
||||
self.span_to_string(sp, true)
|
||||
self.span_to_string(sp, self.path_mapping.filename_display_for_diagnostics)
|
||||
}
|
||||
|
||||
pub fn span_to_filename(&self, sp: Span) -> FileName {
|
||||
self.lookup_char_pos(sp.lo()).file.name.clone()
|
||||
}
|
||||
|
||||
pub fn filename_for_diagnostics<'a>(&self, filename: &'a FileName) -> FileNameDisplay<'a> {
|
||||
filename.display(self.path_mapping.filename_display_for_diagnostics)
|
||||
}
|
||||
|
||||
pub fn is_multiline(&self, sp: Span) -> bool {
|
||||
let lo = self.lookup_source_file_idx(sp.lo());
|
||||
let hi = self.lookup_source_file_idx(sp.hi());
|
||||
|
@ -1013,15 +1017,22 @@ impl SourceMap {
|
|||
#[derive(Clone)]
|
||||
pub struct FilePathMapping {
|
||||
mapping: Vec<(PathBuf, PathBuf)>,
|
||||
filename_display_for_diagnostics: FileNameDisplayPreference,
|
||||
}
|
||||
|
||||
impl FilePathMapping {
|
||||
pub fn empty() -> FilePathMapping {
|
||||
FilePathMapping { mapping: vec![] }
|
||||
FilePathMapping::new(Vec::new())
|
||||
}
|
||||
|
||||
pub fn new(mapping: Vec<(PathBuf, PathBuf)>) -> FilePathMapping {
|
||||
FilePathMapping { mapping }
|
||||
let filename_display_for_diagnostics = if mapping.is_empty() {
|
||||
FileNameDisplayPreference::Local
|
||||
} else {
|
||||
FileNameDisplayPreference::Remapped
|
||||
};
|
||||
|
||||
FilePathMapping { mapping, filename_display_for_diagnostics }
|
||||
}
|
||||
|
||||
/// Applies any path prefix substitution as defined by the mapping.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue