Split span_to_string into span_to_diagnostic/embeddable_string
This commit is contained in:
parent
0ac9ca4f88
commit
37dbe868c9
13 changed files with 60 additions and 24 deletions
|
@ -406,7 +406,7 @@ impl SourceMap {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn span_to_string(&self, sp: Span) -> String {
|
||||
fn span_to_string(&self, sp: Span, prefer_local: bool) -> String {
|
||||
if self.files.borrow().source_files.is_empty() && sp.is_dummy() {
|
||||
return "no-location".to_string();
|
||||
}
|
||||
|
@ -415,7 +415,7 @@ impl SourceMap {
|
|||
let hi = self.lookup_char_pos(sp.hi());
|
||||
format!(
|
||||
"{}:{}:{}: {}:{}",
|
||||
lo.file.name.prefer_remapped(),
|
||||
if prefer_local { lo.file.name.prefer_local() } else { lo.file.name.prefer_remapped() },
|
||||
lo.line,
|
||||
lo.col.to_usize() + 1,
|
||||
hi.line,
|
||||
|
@ -423,6 +423,18 @@ 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)
|
||||
}
|
||||
|
||||
/// 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)
|
||||
}
|
||||
|
||||
pub fn span_to_filename(&self, sp: Span) -> FileName {
|
||||
self.lookup_char_pos(sp.lo()).file.name.clone()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue