From bc031d4c744f0a1542ce2706f25b843aba205f8c Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 7 May 2019 14:48:00 +0200 Subject: [PATCH] Properly hash enums --- clippy_lints/src/consts.rs | 1 + clippy_lints/src/utils/hir_utils.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index c96c7e7e857..cbc10768bbc 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -81,6 +81,7 @@ fn hash(&self, state: &mut H) where H: Hasher, { + std::mem::discriminant(self).hash(state); match *self { Constant::Str(ref s) => { s.hash(state); diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index de129900467..88b88c2c74a 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -389,10 +389,18 @@ pub fn hash_block(&mut self, b: &Block) { #[allow(clippy::many_single_char_names, clippy::too_many_lines)] pub fn hash_expr(&mut self, e: &Expr) { - if let Some(e) = constant_simple(self.cx, self.tables, e) { + let simple_const = constant_simple(self.cx, self.tables, e); + + // const hashing may result in the same hash as some unrelated node, so add a sort of + // discriminant depending on which path we're choosing next + simple_const.is_some().hash(&mut self.s); + + if let Some(e) = simple_const { return e.hash(&mut self.s); } + std::mem::discriminant(&e.node).hash(&mut self.s); + match e.node { ExprKind::AddrOf(m, ref e) => { let c: fn(_, _) -> _ = ExprKind::AddrOf; -- 2.44.0