about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZack M. Davis <code@zackmdavis.net>2017-06-29 12:07:30 -0700
committerZack M. Davis <code@zackmdavis.net>2017-07-21 16:50:44 -0700
commit6043ce9f7559e33fd173af80109137ec0ef999e1 (patch)
tree32dee429ecc8771f3c75a2c04fd4f6474503a29a
parent15aa15b03f41278aa5b9e56975889929ee734c63 (diff)
downloadrust-6043ce9f7559e33fd173af80109137ec0ef999e1.tar.gz
rust-6043ce9f7559e33fd173af80109137ec0ef999e1.zip
make JSON error byte position start at top of file
The `hi` and `lo` offsets in a span are relative to a `CodeMap`, but this
doesn't seem to be terribly useful for tool consumers who don't have the
codemap, but might want the byte offset within an actual file?

Resolves #35164.
-rw-r--r--src/libsyntax/json.rs5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/libsyntax/json.rs b/src/libsyntax/json.rs
index 909b0031d61..695c740f405 100644
--- a/src/libsyntax/json.rs
+++ b/src/libsyntax/json.rs
@@ -256,8 +256,8 @@ impl DiagnosticSpan {
         });
         DiagnosticSpan {
             file_name: start.file.name.clone(),
-            byte_start: span.lo.0,
-            byte_end: span.hi.0,
+            byte_start: span.lo.0 - start.file.start_pos.0,
+            byte_end: span.hi.0 - start.file.start_pos.0,
             line_start: start.line,
             line_end: end.line,
             column_start: start.col.0 + 1,
@@ -362,4 +362,3 @@ impl JsonEmitter {
         suggestion.splice_lines(&*self.cm).iter().map(|line| line.0.to_owned()).collect()
     }
 }
-