about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2019-05-07 14:48:00 +0200
committerflip1995 <hello@philkrones.com>2019-05-14 13:57:48 +0200
commitbc031d4c744f0a1542ce2706f25b843aba205f8c (patch)
tree4fd61d6e5107ad74ea33108ac341b285e05e6147
parent501830bf01422ddbaa3e2014b48c6ec7788e7835 (diff)
downloadrust-bc031d4c744f0a1542ce2706f25b843aba205f8c.tar.gz
rust-bc031d4c744f0a1542ce2706f25b843aba205f8c.zip
Properly hash enums
-rw-r--r--clippy_lints/src/consts.rs1
-rw-r--r--clippy_lints/src/utils/hir_utils.rs10
2 files changed, 10 insertions, 1 deletions
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 @@ impl Hash for Constant {
     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 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
 
     #[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;