Skip to content

Commit de81de5

Browse files
committed
Hash attribute contents directly, instead of hashing their spans
This makes the hash of a crate no longer whitespace dependant on it's attributes Ping #14132
1 parent 832e5a0 commit de81de5

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/librustc_back/svh.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,6 @@ impl Svh {
8787
visit::walk_crate(&mut visit, krate);
8888
}
8989

90-
// FIXME (#14132): This hash is still sensitive to e.g. the
91-
// spans of the crate Attributes and their underlying
92-
// MetaItems; we should make ContentHashable impl for those
93-
// types and then use hash_content. But, since all crate
94-
// attributes should appear near beginning of the file, it is
95-
// not such a big deal to be sensitive to their spans for now.
96-
//
97-
// We hash only the MetaItems instead of the entire Attribute
98-
// to avoid hashing the AttrId
99-
for attr in &krate.attrs {
100-
attr.node.value.hash(&mut state);
101-
}
102-
10390
let hash = state.finish();
10491
return Svh {
10592
hash: (0..64).step_by(4).map(|i| hex(hash >> i)).collect()
@@ -198,6 +185,9 @@ mod svh_visitor {
198185
SawPat,
199186
SawLocal,
200187
SawArm,
188+
SawAttrWord,
189+
SawAttrList,
190+
SawAttrNameValue,
201191
SawExpr(SawExprComponent<'a>),
202192
SawStmt(SawStmtComponent),
203193
}
@@ -487,5 +477,26 @@ mod svh_visitor {
487477
fn visit_arm(&mut self, a: &Arm) {
488478
SawArm.hash(self.st); visit::walk_arm(self, a)
489479
}
480+
481+
fn visit_attribute(&mut self, a: &Attribute) {
482+
let ref val = a.node.value;
483+
484+
match val.node {
485+
MetaItem_::MetaWord(ref s) => {
486+
SawAttrWord.hash(self.st);
487+
s.hash(self.st);
488+
},
489+
MetaItem_::MetaList(ref s, ref items) => {
490+
SawAttrList.hash(self.st);
491+
s.hash(self.st);
492+
items.hash(self.st);
493+
},
494+
MetaItem_::MetaNameValue(ref s, ref lit) => {
495+
SawAttrNameValue.hash(self.st);
496+
s.hash(self.st);
497+
lit.hash(self.st);
498+
},
499+
}
500+
}
490501
}
491502
}

0 commit comments

Comments
 (0)