]> git.lizzy.rs Git - rust.git/commitdiff
Properly hash enums
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Tue, 7 May 2019 12:48:00 +0000 (14:48 +0200)
committerflip1995 <hello@philkrones.com>
Tue, 14 May 2019 11:57:48 +0000 (13:57 +0200)
clippy_lints/src/consts.rs
clippy_lints/src/utils/hir_utils.rs

index c96c7e7e857a3b4dc777bc546f34fc855e176eaa..cbc10768bbc1604dc7b24e0fd395750a5616a9cd 100644 (file)
@@ -81,6 +81,7 @@ fn hash<H>(&self, state: &mut H)
     where
         H: Hasher,
     {
+        std::mem::discriminant(self).hash(state);
         match *self {
             Constant::Str(ref s) => {
                 s.hash(state);
index de12990046781950b3eb86171d18c6d5d713b46b..88b88c2c74ab717dcbded590bd584874d3d88012 100644 (file)
@@ -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;