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/librustc/ich/impls_syntax.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/librustc/ich/impls_syntax.rs')
| -rw-r--r-- | src/librustc/ich/impls_syntax.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index dc1f6fd3131..2510d7efb59 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -425,6 +425,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile { ref lines, ref multibyte_chars, ref non_narrow_chars, + ref normalized_pos, } = *self; (name_hash as u64).hash_stable(hcx, hasher); @@ -453,6 +454,12 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile { for &char_pos in non_narrow_chars.iter() { stable_non_narrow_char(char_pos, start_pos).hash_stable(hcx, hasher); } + + normalized_pos.len().hash_stable(hcx, hasher); + for &char_pos in normalized_pos.iter() { + stable_normalized_pos(char_pos, start_pos).hash_stable(hcx, hasher); + } + } } @@ -482,6 +489,18 @@ fn stable_non_narrow_char(swc: ::syntax_pos::NonNarrowChar, (pos.0 - source_file_start.0, width as u32) } +fn stable_normalized_pos(np: ::syntax_pos::NormalizedPos, + source_file_start: ::syntax_pos::BytePos) + -> (u32, u32) { + let ::syntax_pos::NormalizedPos { + pos, + diff + } = np; + + (pos.0 - source_file_start.0, diff) +} + + impl<'tcx> HashStable<StableHashingContext<'tcx>> for feature_gate::Features { fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) { // Unfortunately we cannot exhaustively list fields here, since the |
