diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-10-25 13:12:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-25 13:12:45 +0200 |
| commit | 1f93be1bb3f89d6b30a3ddc39e8a462924ccd503 (patch) | |
| tree | ddc93b333040abfda9dd252818e026760f8e0fa3 /src/libsyntax/source_map.rs | |
| parent | 959b6e324ce2786a4adade6cef222ffbd20f3791 (diff) | |
| parent | ff1860ad763baac652d3a43a93985e29ade805cb (diff) | |
| download | rust-1f93be1bb3f89d6b30a3ddc39e8a462924ccd503.tar.gz rust-1f93be1bb3f89d6b30a3ddc39e8a462924ccd503.zip | |
Rollup merge of #65074 - Rantanen:json-byte-pos, r=matklad
Fix the start/end byte positions in the compiler JSON output Track the changes made during normalization in the `SourceFile` and use this information to correct the `start_byte` and `end_byte` fields in the JSON output. This should ensure the start/end byte fields can be used to index the original file, even if Rust normalized the source code for parsing purposes. Both CRLF to LF and BOM removal are handled with this one. The rough plan was discussed with @matklad in rust-lang-nursery/rustfix#176 - although I ended up going with `u32` offset tracking so I wouldn't need to deal with `u32 + i32` arithmetics when applying the offset to the span byte positions. Fixes #65029
Diffstat (limited to 'src/libsyntax/source_map.rs')
| -rw-r--r-- | src/libsyntax/source_map.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/libsyntax/source_map.rs b/src/libsyntax/source_map.rs index a1d147637e2..d7760e0cf9e 100644 --- a/src/libsyntax/source_map.rs +++ b/src/libsyntax/source_map.rs @@ -283,6 +283,7 @@ impl SourceMap { mut file_local_lines: Vec<BytePos>, mut file_local_multibyte_chars: Vec<MultiByteChar>, mut file_local_non_narrow_chars: Vec<NonNarrowChar>, + mut file_local_normalized_pos: Vec<NormalizedPos>, ) -> Lrc<SourceFile> { let start_pos = self.next_start_pos(); @@ -301,6 +302,10 @@ impl SourceMap { *swc = *swc + start_pos; } + for nc in &mut file_local_normalized_pos { + nc.pos = nc.pos + start_pos; + } + let source_file = Lrc::new(SourceFile { name: filename, name_was_remapped, @@ -314,6 +319,7 @@ impl SourceMap { lines: file_local_lines, multibyte_chars: file_local_multibyte_chars, non_narrow_chars: file_local_non_narrow_chars, + normalized_pos: file_local_normalized_pos, name_hash, }); |
