diff options
| author | bors <bors@rust-lang.org> | 2021-01-11 21:32:50 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-01-11 21:32:50 +0000 |
| commit | fe531d5a5f1404281e3fb237daaf87b8180bd13d (patch) | |
| tree | 4262687b80126dd9f2012656db4e205df95acbb8 /compiler/rustc_span/src/lib.rs | |
| parent | c5eae562935922f712edec56a45591bc2f8ded1c (diff) | |
| parent | 75de8286c04af256762804ee96b08a68d2aba279 (diff) | |
| download | rust-fe531d5a5f1404281e3fb237daaf87b8180bd13d.tar.gz rust-fe531d5a5f1404281e3fb237daaf87b8180bd13d.zip | |
Auto merge of #79012 - tgnottingham:span_data_to_lines_and_cols, r=estebank
rustc_span: add span_data_to_lines_and_cols to caching source map view
Diffstat (limited to 'compiler/rustc_span/src/lib.rs')
| -rw-r--r-- | compiler/rustc_span/src/lib.rs | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 62ca7b066d9..f0f9f940446 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -1871,6 +1871,10 @@ pub trait HashStableContext { &mut self, byte: BytePos, ) -> Option<(Lrc<SourceFile>, usize, BytePos)>; + fn span_data_to_lines_and_cols( + &mut self, + span: &SpanData, + ) -> Option<(Lrc<SourceFile>, usize, BytePos, usize, BytePos)>; } impl<CTX> HashStable<CTX> for Span @@ -1904,22 +1908,8 @@ where // position that belongs to it, as opposed to hashing the first // position past it. let span = self.data(); - let (file_lo, line_lo, col_lo) = match ctx.byte_pos_to_line_and_col(span.lo) { - Some(pos) => pos, - None => { - Hash::hash(&TAG_INVALID_SPAN, hasher); - span.ctxt.hash_stable(ctx, hasher); - return; - } - }; - - if !file_lo.contains(span.hi) { - Hash::hash(&TAG_INVALID_SPAN, hasher); - span.ctxt.hash_stable(ctx, hasher); - return; - } - - let (_, line_hi, col_hi) = match ctx.byte_pos_to_line_and_col(span.hi) { + let (file, line_lo, col_lo, line_hi, col_hi) = match ctx.span_data_to_lines_and_cols(&span) + { Some(pos) => pos, None => { Hash::hash(&TAG_INVALID_SPAN, hasher); @@ -1931,7 +1921,7 @@ where Hash::hash(&TAG_VALID_SPAN, hasher); // We truncate the stable ID hash and line and column numbers. The chances // of causing a collision this way should be minimal. - Hash::hash(&(file_lo.name_hash as u64), hasher); + Hash::hash(&(file.name_hash as u64), hasher); // Hash both the length and the end location (line/column) of a span. If we // hash only the length, for example, then two otherwise equal spans with |
