1
Fork 0

Address review comments.

This commit is contained in:
Nicholas Nethercote 2022-06-02 11:43:14 +10:00
parent 0b81d7cdc6
commit 72de7c4102
3 changed files with 70 additions and 51 deletions

View file

@ -5,7 +5,7 @@ use crate::ich::StableHashingContext;
use rustc_ast as ast;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_span::{BytePos, NormalizedPos, SourceFile, SourceFileLines};
use rustc_span::{BytePos, NormalizedPos, SourceFile};
use std::assert_matches::assert_matches;
use smallvec::SmallVec;
@ -60,7 +60,7 @@ impl<'ctx> rustc_ast::HashStableContext for StableHashingContext<'ctx> {
impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let SourceFile {
ref name, // We hash the smaller name_hash instead of this
name: _, // We hash the smaller name_hash instead of this
name_hash,
cnum,
// Do not hash the source as it is not encoded
@ -69,7 +69,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
external_src: _,
start_pos,
end_pos: _,
ref lines,
lines: _,
ref multibyte_chars,
ref non_narrow_chars,
ref normalized_pos,
@ -79,18 +79,15 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
src_hash.hash_stable(hcx, hasher);
// We only hash the relative position within this source_file
match &*lines.borrow() {
SourceFileLines::Lines { lines } => {
lines.len().hash_stable(hcx, hasher);
for &line in lines.iter() {
stable_byte_pos(line, start_pos).hash_stable(hcx, hasher);
}
// We are always in `Lines` form by the time we reach here.
assert!(self.lines.borrow().is_lines());
self.lines(|lines| {
// We only hash the relative position within this source_file
lines.len().hash_stable(hcx, hasher);
for &line in lines.iter() {
stable_byte_pos(line, start_pos).hash_stable(hcx, hasher);
}
SourceFileLines::Diffs { .. } => {
panic!("called hash_stable on SourceFileLines::Diffs for {:?}", name);
}
}
});
// We only hash the relative position within this source_file
multibyte_chars.len().hash_stable(hcx, hasher);