Skip to content

Commit bc031d4

Browse files
oli-obkflip1995
authored andcommitted
Properly hash enums
1 parent 501830b commit bc031d4

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
@@ -81,6 +81,7 @@ impl Hash for Constant {
8181
where
8282
H: Hasher,
8383
{
84+
std::mem::discriminant(self).hash(state);
8485
match *self {
8586
Constant::Str(ref s) => {
8687
s.hash(state);

clippy_lints/src/utils/hir_utils.rs

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

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

402+
std::mem::discriminant(&e.node).hash(&mut self.s);
403+
396404
match e.node {
397405
ExprKind::AddrOf(m, ref e) => {
398406
let c: fn(_, _) -> _ = ExprKind::AddrOf;

0 commit comments

Comments
 (0)