Skip to content

Commit 5417b45

Browse files
committed
Use local and remapped paths where appropriate
1 parent fb4f643 commit 5417b45

File tree

28 files changed

+85
-74
lines changed

28 files changed

+85
-74
lines changed

compiler/rustc_builtin_macros/src/source_util.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ pub fn expand_file(
6161

6262
let topmost = cx.expansion_cause().unwrap_or(sp);
6363
let loc = cx.source_map().lookup_char_pos(topmost.lo());
64-
base::MacEager::expr(cx.expr_str(topmost, Symbol::intern(&loc.file.name.to_string())))
64+
base::MacEager::expr(
65+
cx.expr_str(topmost, Symbol::intern(&loc.file.name.prefer_remapped().to_string_lossy())),
66+
)
6567
}
6668

6769
pub fn expand_stringify(

compiler/rustc_codegen_cranelift/src/common.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,9 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
334334
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
335335
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
336336
let const_loc = self.tcx.const_caller_location((
337-
rustc_span::symbol::Symbol::intern(&caller.file.name.to_string()),
337+
rustc_span::symbol::Symbol::intern(
338+
&caller.file.name.prefer_remapped().to_string_lossy(),
339+
),
338340
caller.line as u32,
339341
caller.col_display as u32 + 1,
340342
));

compiler/rustc_codegen_cranelift/src/debuginfo/line_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn line_program_add_file(
8787
filename => {
8888
let dir_id = line_program.default_directory();
8989
let dummy_file_name = LineString::new(
90-
filename.to_string().into_bytes(),
90+
filename.prefer_remapped().to_string().into_bytes(),
9191
line_program.encoding(),
9292
line_strings,
9393
);

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,10 +759,10 @@ fn hex_encode(data: &[u8]) -> String {
759759
}
760760

761761
pub fn file_metadata(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) -> &'ll DIFile {
762-
debug!("file_metadata: file_name: {}", source_file.name);
762+
debug!("file_metadata: file_name: {:?}", source_file.name);
763763

764764
let hash = Some(&source_file.src_hash);
765-
let file_name = Some(source_file.name.to_string());
765+
let file_name = Some(source_file.name.prefer_remapped().to_string());
766766
let directory = if source_file.is_real_file() && !source_file.is_imported() {
767767
Some(cx.sess().working_dir.to_string_lossy(false).to_string())
768768
} else {

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11441144
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
11451145
let caller = tcx.sess.source_map().lookup_char_pos(topmost.lo());
11461146
let const_loc = tcx.const_caller_location((
1147-
Symbol::intern(&caller.file.name.to_string()),
1147+
Symbol::intern(&caller.file.name.prefer_remapped().to_string_lossy()),
11481148
caller.line as u32,
11491149
caller.col_display as u32 + 1,
11501150
));

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ impl AnnotateSnippetEmitterWriter {
126126
}
127127
// owned: line source, line index, annotations
128128
type Owned = (String, usize, Vec<crate::snippet::Annotation>);
129-
let origin = primary_lo.file.name.to_string();
129+
let filename = primary_lo.file.name.prefer_local();
130+
let origin = filename.to_string_lossy();
130131
let annotated_files: Vec<Owned> = annotated_files
131132
.into_iter()
132133
.flat_map(|annotated_file| {

compiler/rustc_errors/src/emitter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ impl EmitterWriter {
13091309
buffer_msg_line_offset,
13101310
&format!(
13111311
"{}:{}:{}",
1312-
loc.file.name,
1312+
loc.file.name.prefer_local(),
13131313
sm.doctest_offset_line(&loc.file.name, loc.line),
13141314
loc.col.0 + 1,
13151315
),
@@ -1323,7 +1323,7 @@ impl EmitterWriter {
13231323
0,
13241324
&format!(
13251325
"{}:{}:{}: ",
1326-
loc.file.name,
1326+
loc.file.name.prefer_local(),
13271327
sm.doctest_offset_line(&loc.file.name, loc.line),
13281328
loc.col.0 + 1,
13291329
),
@@ -1347,12 +1347,12 @@ impl EmitterWriter {
13471347
};
13481348
format!(
13491349
"{}:{}{}",
1350-
annotated_file.file.name,
1350+
annotated_file.file.name.prefer_local(),
13511351
sm.doctest_offset_line(&annotated_file.file.name, first_line.line_index),
13521352
col
13531353
)
13541354
} else {
1355-
annotated_file.file.name.to_string()
1355+
format!("{}", annotated_file.file.name.prefer_local())
13561356
};
13571357
buffer.append(buffer_msg_line_offset + 1, &loc, Style::LineAndColumn);
13581358
for _ in 0..max_line_num_len {

compiler/rustc_errors/src/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ impl DiagnosticSpan {
468468
});
469469

470470
DiagnosticSpan {
471-
file_name: start.file.name.to_string(),
471+
file_name: start.file.name.prefer_local().to_string(),
472472
byte_start: start.file.original_relative_byte_pos(span.lo()).0,
473473
byte_end: start.file.original_relative_byte_pos(span.hi()).0,
474474
line_start: start.line,

compiler/rustc_expand/src/base.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,10 @@ impl<'a> ExtCtxt<'a> {
10801080
other => {
10811081
return Err(self.struct_span_err(
10821082
span,
1083-
&format!("cannot resolve relative path in non-file source `{}`", other),
1083+
&format!(
1084+
"cannot resolve relative path in non-file source `{}`",
1085+
other.prefer_local()
1086+
),
10841087
));
10851088
}
10861089
};

compiler/rustc_expand/src/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
365365
FileName::Real(name) => name
366366
.into_local_path()
367367
.expect("attempting to resolve a file path in an external file"),
368-
other => PathBuf::from(other.to_string()),
368+
other => PathBuf::from(other.prefer_local().to_string()),
369369
};
370370
let dir_path = file_path.parent().unwrap_or(&file_path).to_owned();
371371
self.cx.root_path = dir_path.clone();

0 commit comments

Comments
 (0)