Skip to content

Commit e400792

Browse files
committed
Properly hash enums
1 parent 089a7be commit e400792

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

clippy_lints/src/consts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl Hash for Constant {
8282
where
8383
H: Hasher,
8484
{
85+
std::mem::discriminant(self).hash(state);
8586
match *self {
8687
Constant::Str(ref s) => {
8788
s.hash(state);

clippy_lints/src/utils/hir_utils.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,18 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
392392

393393
#[allow(clippy::many_single_char_names, clippy::too_many_lines)]
394394
pub fn hash_expr(&mut self, e: &Expr) {
395-
if let Some(e) = constant_simple(self.cx, self.tables, e) {
395+
let simple_const = constant_simple(self.cx, self.tables, e);
396+
397+
// const hashing may result in the same hash as some unrelated node, so add a sort of
398+
// discriminant depending on which path we're choosing next
399+
simple_const.is_some().hash(&mut self.s);
400+
401+
if let Some(e) = simple_const {
396402
return e.hash(&mut self.s);
397403
}
398404

405+
std::mem::discriminant(&e.node).hash(&mut self.s);
406+
399407
match e.node {
400408
ExprKind::AddrOf(m, ref e) => {
401409
let c: fn(_, _) -> _ = ExprKind::AddrOf;

0 commit comments

Comments
 (0)