1
Fork 0

Shorten trimmed display of closures

When `with_forced_trimmed_paths` is used, only print filename and start
of the closure's span, to reduce their verbosity.
This commit is contained in:
Esteban Küber 2022-12-13 16:34:04 -08:00
parent 30ae261c42
commit 4d4d4786f9
6 changed files with 28 additions and 8 deletions

View file

@ -438,7 +438,11 @@ impl SourceMap {
}
}
fn span_to_string(&self, sp: Span, filename_display_pref: FileNameDisplayPreference) -> String {
pub 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();
}
@ -446,12 +450,15 @@ impl SourceMap {
let lo = self.lookup_char_pos(sp.lo());
let hi = self.lookup_char_pos(sp.hi());
format!(
"{}:{}:{}: {}:{}",
"{}:{}:{}{}",
lo.file.name.display(filename_display_pref),
lo.line,
lo.col.to_usize() + 1,
hi.line,
hi.col.to_usize() + 1,
if let FileNameDisplayPreference::Short = filename_display_pref {
String::new()
} else {
format!(": {}:{}", hi.line, hi.col.to_usize() + 1)
}
)
}