Auto merge of #83813 - cbeuw:remap-std, r=michaelwoerister
Fix `--remap-path-prefix` not correctly remapping `rust-src` component paths and unify handling of path mapping with virtualized paths This PR fixes #73167 ("Binaries end up containing path to the rust-src component despite `--remap-path-prefix`") by preventing real local filesystem paths from reaching compilation output if the path is supposed to be remapped. `RealFileName::Named` introduced in #72767 is now renamed as `LocalPath`, because this variant wraps a (most likely) valid local filesystem path. `RealFileName::Devirtualized` is renamed as `Remapped` to be used for remapped path from a real path via `--remap-path-prefix` argument, as well as real path inferred from a virtualized (during compiler bootstrapping) `/rustc/...` path. The `local_path` field is now an `Option<PathBuf>`, as it will be set to `None` before serialisation, so it never reaches any build output. Attempting to serialise a non-`None` `local_path` will cause an assertion faliure. When a path is remapped, a `RealFileName::Remapped` variant is created. The original path is preserved in `local_path` field and the remapped path is saved in `virtual_name` field. Previously, the `local_path` is directly modified which goes against its purpose of "suitable for reading from the file system on the local host". `rustc_span::SourceFile`'s fields `unmapped_path` (introduced by #44940) and `name_was_remapped` (introduced by #41508 when `--remap-path-prefix` feature originally added) are removed, as these two pieces of information can be inferred from the `name` field: if it's anything other than a `FileName::Real(_)`, or if it is a `FileName::Real(RealFileName::LocalPath(_))`, then clearly `name_was_remapped` would've been false and `unmapped_path` would've been `None`. If it is a `FileName::Real(RealFileName::Remapped{local_path, virtual_name})`, then `name_was_remapped` would've been true and `unmapped_path` would've been `Some(local_path)`. cc `@eddyb` who implemented `/rustc/...` path devirtualisation
This commit is contained in:
commit
e1ff91f439
48 changed files with 442 additions and 265 deletions
|
@ -76,7 +76,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
for constraint in &constraints {
|
||||
let OutlivesConstraint { sup, sub, locations, category } = constraint;
|
||||
let (name, arg) = match locations {
|
||||
Locations::All(span) => ("All", tcx.sess.source_map().span_to_string(*span)),
|
||||
Locations::All(span) => {
|
||||
("All", tcx.sess.source_map().span_to_embeddable_string(*span))
|
||||
}
|
||||
Locations::Single(loc) => ("Single", format!("{:?}", loc)),
|
||||
};
|
||||
with_msg(&format!("{:?}: {:?} due to {:?} at {}({})", sup, sub, category, name, arg))?;
|
||||
|
|
|
@ -263,7 +263,13 @@ impl<'tcx> fmt::Display for FrameInfo<'tcx> {
|
|||
}
|
||||
if !self.span.is_dummy() {
|
||||
let lo = tcx.sess.source_map().lookup_char_pos(self.span.lo());
|
||||
write!(f, " at {}:{}:{}", lo.file.name, lo.line, lo.col.to_usize() + 1)?;
|
||||
write!(
|
||||
f,
|
||||
" at {}:{}:{}",
|
||||
lo.file.name.prefer_local(),
|
||||
lo.line,
|
||||
lo.col.to_usize() + 1
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
|
|
|
@ -106,7 +106,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
|
||||
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
|
||||
(
|
||||
Symbol::intern(&caller.file.name.to_string()),
|
||||
Symbol::intern(&caller.file.name.prefer_remapped().to_string_lossy()),
|
||||
u32::try_from(caller.line).unwrap(),
|
||||
u32::try_from(caller.col_display).unwrap().checked_add(1).unwrap(),
|
||||
)
|
||||
|
|
|
@ -169,8 +169,8 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
|
|||
debug!(
|
||||
"instrumenting {:?}, fn sig span: {}, body span: {}",
|
||||
def_id,
|
||||
source_map.span_to_string(fn_sig_span),
|
||||
source_map.span_to_string(body_span)
|
||||
source_map.span_to_diagnostic_string(fn_sig_span),
|
||||
source_map.span_to_diagnostic_string(body_span)
|
||||
);
|
||||
|
||||
let mut graphviz_data = debug::GraphvizData::new();
|
||||
|
@ -311,7 +311,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
|
|||
let tcx = self.tcx;
|
||||
let source_map = tcx.sess.source_map();
|
||||
let body_span = self.body_span;
|
||||
let file_name = Symbol::intern(&self.source_file.name.to_string());
|
||||
let file_name = Symbol::intern(&self.source_file.name.prefer_remapped().to_string_lossy());
|
||||
|
||||
let mut bcb_counters = IndexVec::from_elem_n(None, self.basic_coverage_blocks.num_nodes());
|
||||
for covspan in coverage_spans {
|
||||
|
@ -332,8 +332,8 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
|
|||
"Calling make_code_region(file_name={}, source_file={:?}, span={}, body_span={})",
|
||||
file_name,
|
||||
self.source_file,
|
||||
source_map.span_to_string(span),
|
||||
source_map.span_to_string(body_span)
|
||||
source_map.span_to_diagnostic_string(span),
|
||||
source_map.span_to_diagnostic_string(body_span)
|
||||
);
|
||||
|
||||
inject_statement(
|
||||
|
|
|
@ -445,7 +445,10 @@ impl Visitor<'tcx> for ExtraComments<'tcx> {
|
|||
ty::Tuple(tys) if tys.is_empty() => {}
|
||||
_ => {
|
||||
self.push("mir::Constant");
|
||||
self.push(&format!("+ span: {}", self.tcx.sess.source_map().span_to_string(*span)));
|
||||
self.push(&format!(
|
||||
"+ span: {}",
|
||||
self.tcx.sess.source_map().span_to_embeddable_string(*span)
|
||||
));
|
||||
if let Some(user_ty) = user_ty {
|
||||
self.push(&format!("+ user_ty: {:?}", user_ty));
|
||||
}
|
||||
|
@ -516,7 +519,7 @@ impl Visitor<'tcx> for ExtraComments<'tcx> {
|
|||
}
|
||||
|
||||
fn comment(tcx: TyCtxt<'_>, SourceInfo { span, scope }: SourceInfo) -> String {
|
||||
format!("scope {} at {}", scope.index(), tcx.sess.source_map().span_to_string(span))
|
||||
format!("scope {} at {}", scope.index(), tcx.sess.source_map().span_to_embeddable_string(span))
|
||||
}
|
||||
|
||||
/// Prints local variables in a scope tree.
|
||||
|
@ -617,7 +620,7 @@ fn write_scope_tree(
|
|||
"{0:1$} // at {2}",
|
||||
indented_header,
|
||||
ALIGN,
|
||||
tcx.sess.source_map().span_to_string(span),
|
||||
tcx.sess.source_map().span_to_embeddable_string(span),
|
||||
)?;
|
||||
} else {
|
||||
writeln!(w, "{}", indented_header)?;
|
||||
|
@ -1004,7 +1007,7 @@ fn write_user_type_annotations(
|
|||
"| {:?}: {:?} at {}",
|
||||
index.index(),
|
||||
annotation.user_ty,
|
||||
tcx.sess.source_map().span_to_string(annotation.span)
|
||||
tcx.sess.source_map().span_to_embeddable_string(annotation.span)
|
||||
)?;
|
||||
}
|
||||
if !body.user_type_annotations.is_empty() {
|
||||
|
|
|
@ -628,7 +628,7 @@ fn tooltip<'tcx>(
|
|||
) -> String {
|
||||
let source_map = tcx.sess.source_map();
|
||||
let mut text = Vec::new();
|
||||
text.push(format!("{}: {}:", spanview_id, &source_map.span_to_string(span)));
|
||||
text.push(format!("{}: {}:", spanview_id, &source_map.span_to_embeddable_string(span)));
|
||||
for statement in statements {
|
||||
let source_range = source_range_no_file(tcx, &statement.source_info.span);
|
||||
text.push(format!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue