]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/utils/hir_utils.rs
Also hash mem::discriminant in hash_stmt
[rust.git] / clippy_lints / src / utils / hir_utils.rs
index 939b4f595e4d09a9d32440aba3e0aae44ff3ce6f..77d6a52f57f2dfb4fe3c8308206ddba118866285 100644 (file)
@@ -1,12 +1,12 @@
-use crate::consts::{constant_simple, constant_context};
-use rustc::lint::LateContext;
+use crate::consts::{constant_context, constant_simple};
+use crate::utils::differing_macro_contexts;
 use rustc::hir::*;
-use rustc::ty::{TypeckTables};
-use std::hash::{Hash, Hasher};
+use rustc::lint::LateContext;
+use rustc::ty::TypeckTables;
 use std::collections::hash_map::DefaultHasher;
+use std::hash::{Hash, Hasher};
 use syntax::ast::Name;
 use syntax::ptr::P;
-use crate::utils::differing_macro_contexts;
 
 /// Type used to check whether two ast are the same. This is different from the
 /// operator
@@ -40,46 +40,52 @@ pub fn ignore_fn(self) -> Self {
         }
     }
 
-    /// Check whether two statements are the same.
+    /// Checks whether two statements are the same.
     pub fn eq_stmt(&mut self, left: &Stmt, right: &Stmt) -> bool {
         match (&left.node, &right.node) {
-            (&StmtKind::Decl(ref l, _), &StmtKind::Decl(ref r, _)) => {
-                if let (&DeclKind::Local(ref l), &DeclKind::Local(ref r)) = (&l.node, &r.node) {
-                    both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r)) && both(&l.init, &r.init, |l, r| self.eq_expr(l, r))
-                } else {
-                    false
-                }
+            (&StmtKind::Local(ref l), &StmtKind::Local(ref r)) => {
+                self.eq_pat(&l.pat, &r.pat)
+                    && both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r))
+                    && both(&l.init, &r.init, |l, r| self.eq_expr(l, r))
             },
-            (&StmtKind::Expr(ref l, _), &StmtKind::Expr(ref r, _)) | (&StmtKind::Semi(ref l, _), &StmtKind::Semi(ref r, _)) => {
+            (&StmtKind::Expr(ref l), &StmtKind::Expr(ref r)) | (&StmtKind::Semi(ref l), &StmtKind::Semi(ref r)) => {
                 self.eq_expr(l, r)
             },
             _ => false,
         }
     }
 
-    /// Check whether two blocks are the same.
+    /// Checks whether two blocks are the same.
     pub fn eq_block(&mut self, left: &Block, right: &Block) -> bool {
         over(&left.stmts, &right.stmts, |l, r| self.eq_stmt(l, r))
             && both(&left.expr, &right.expr, |l, r| self.eq_expr(l, r))
     }
 
+    #[allow(clippy::similar_names)]
     pub fn eq_expr(&mut self, left: &Expr, right: &Expr) -> bool {
         if self.ignore_fn && differing_macro_contexts(left.span, right.span) {
             return false;
         }
 
-        if let (Some(l), Some(r)) = (constant_simple(self.cx, self.tables, left), constant_simple(self.cx, self.tables, right)) {
+        if let (Some(l), Some(r)) = (
+            constant_simple(self.cx, self.tables, left),
+            constant_simple(self.cx, self.tables, right),
+        ) {
             if l == r {
                 return true;
             }
         }
 
         match (&left.node, &right.node) {
-            (&ExprKind::AddrOf(l_mut, ref le), &ExprKind::AddrOf(r_mut, ref re)) => l_mut == r_mut && self.eq_expr(le, re),
+            (&ExprKind::AddrOf(l_mut, ref le), &ExprKind::AddrOf(r_mut, ref re)) => {
+                l_mut == r_mut && self.eq_expr(le, re)
+            },
             (&ExprKind::Continue(li), &ExprKind::Continue(ri)) => {
                 both(&li.label, &ri.label, |l, r| l.ident.as_str() == r.ident.as_str())
             },
-            (&ExprKind::Assign(ref ll, ref lr), &ExprKind::Assign(ref rl, ref rr)) => self.eq_expr(ll, rl) && self.eq_expr(lr, rr),
+            (&ExprKind::Assign(ref ll, ref lr), &ExprKind::Assign(ref rl, ref rr)) => {
+                self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
+            },
             (&ExprKind::AssignOp(ref lo, ref ll, ref lr), &ExprKind::AssignOp(ref ro, ref rl, ref rr)) => {
                 lo.node == ro.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
             },
@@ -98,48 +104,56 @@ pub fn eq_expr(&mut self, left: &Expr, right: &Expr) -> bool {
             (&ExprKind::Call(ref l_fun, ref l_args), &ExprKind::Call(ref r_fun, ref r_args)) => {
                 !self.ignore_fn && self.eq_expr(l_fun, r_fun) && self.eq_exprs(l_args, r_args)
             },
-            (&ExprKind::Cast(ref lx, ref lt), &ExprKind::Cast(ref rx, ref rt)) |
-            (&ExprKind::Type(ref lx, ref lt), &ExprKind::Type(ref rx, ref rt)) => self.eq_expr(lx, rx) && self.eq_ty(lt, rt),
+            (&ExprKind::Cast(ref lx, ref lt), &ExprKind::Cast(ref rx, ref rt))
+            | (&ExprKind::Type(ref lx, ref lt), &ExprKind::Type(ref rx, ref rt)) => {
+                self.eq_expr(lx, rx) && self.eq_ty(lt, rt)
+            },
             (&ExprKind::Field(ref l_f_exp, ref l_f_ident), &ExprKind::Field(ref r_f_exp, ref r_f_ident)) => {
                 l_f_ident.name == r_f_ident.name && self.eq_expr(l_f_exp, r_f_exp)
             },
-            (&ExprKind::Index(ref la, ref li), &ExprKind::Index(ref ra, ref ri)) => self.eq_expr(la, ra) && self.eq_expr(li, ri),
-            (&ExprKind::If(ref lc, ref lt, ref le), &ExprKind::If(ref rc, ref rt, ref re)) => {
-                self.eq_expr(lc, rc) && self.eq_expr(&**lt, &**rt) && both(le, re, |l, r| self.eq_expr(l, r))
+            (&ExprKind::Index(ref la, ref li), &ExprKind::Index(ref ra, ref ri)) => {
+                self.eq_expr(la, ra) && self.eq_expr(li, ri)
             },
             (&ExprKind::Lit(ref l), &ExprKind::Lit(ref r)) => l.node == r.node,
             (&ExprKind::Loop(ref lb, ref ll, ref lls), &ExprKind::Loop(ref rb, ref rl, ref rls)) => {
                 lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.as_str() == r.ident.as_str())
             },
             (&ExprKind::Match(ref le, ref la, ref ls), &ExprKind::Match(ref re, ref ra, ref rs)) => {
-                ls == rs && self.eq_expr(le, re) && over(la, ra, |l, r| {
-                    self.eq_expr(&l.body, &r.body) && both(&l.guard, &r.guard, |l, r| self.eq_guard(l, r))
-                        && over(&l.pats, &r.pats, |l, r| self.eq_pat(l, r))
-                })
+                ls == rs
+                    && self.eq_expr(le, re)
+                    && over(la, ra, |l, r| {
+                        self.eq_expr(&l.body, &r.body)
+                            && both(&l.guard, &r.guard, |l, r| self.eq_guard(l, r))
+                            && over(&l.pats, &r.pats, |l, r| self.eq_pat(l, r))
+                    })
             },
             (&ExprKind::MethodCall(ref l_path, _, ref l_args), &ExprKind::MethodCall(ref r_path, _, ref r_args)) => {
                 !self.ignore_fn && self.eq_path_segment(l_path, r_path) && self.eq_exprs(l_args, r_args)
             },
             (&ExprKind::Repeat(ref le, ref ll_id), &ExprKind::Repeat(ref re, ref rl_id)) => {
                 let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id.body));
-                let ll = celcx.expr(&self.cx.tcx.hir.body(ll_id.body).value);
+                let ll = celcx.expr(&self.cx.tcx.hir().body(ll_id.body).value);
                 let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(rl_id.body));
-                let rl = celcx.expr(&self.cx.tcx.hir.body(rl_id.body).value);
+                let rl = celcx.expr(&self.cx.tcx.hir().body(rl_id.body).value);
 
                 self.eq_expr(le, re) && ll == rl
             },
             (&ExprKind::Ret(ref l), &ExprKind::Ret(ref r)) => both(l, r, |l, r| self.eq_expr(l, r)),
             (&ExprKind::Path(ref l), &ExprKind::Path(ref r)) => self.eq_qpath(l, r),
             (&ExprKind::Struct(ref l_path, ref lf, ref lo), &ExprKind::Struct(ref r_path, ref rf, ref ro)) => {
-                self.eq_qpath(l_path, r_path) && both(lo, ro, |l, r| self.eq_expr(l, r))
+                self.eq_qpath(l_path, r_path)
+                    && both(lo, ro, |l, r| self.eq_expr(l, r))
                     && over(lf, rf, |l, r| self.eq_field(l, r))
             },
             (&ExprKind::Tup(ref l_tup), &ExprKind::Tup(ref r_tup)) => self.eq_exprs(l_tup, r_tup),
             (&ExprKind::Unary(l_op, ref le), &ExprKind::Unary(r_op, ref re)) => l_op == r_op && self.eq_expr(le, re),
             (&ExprKind::Array(ref l), &ExprKind::Array(ref r)) => self.eq_exprs(l, r),
             (&ExprKind::While(ref lc, ref lb, ref ll), &ExprKind::While(ref rc, ref rb, ref rl)) => {
-                self.eq_expr(lc, rc) && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.as_str() == r.ident.as_str())
+                self.eq_expr(lc, rc)
+                    && self.eq_block(lb, rb)
+                    && both(ll, rl, |l, r| l.ident.as_str() == r.ident.as_str())
             },
+            (&ExprKind::DropTemps(ref le), &ExprKind::DropTemps(ref re)) => self.eq_expr(le, re),
             _ => false,
         }
     }
@@ -170,14 +184,14 @@ fn eq_lifetime(&mut self, left: &Lifetime, right: &Lifetime) -> bool {
         left.name == right.name
     }
 
-    /// Check whether two patterns are the same.
+    /// Checks whether two patterns are the same.
     pub fn eq_pat(&mut self, left: &Pat, right: &Pat) -> bool {
         match (&left.node, &right.node) {
             (&PatKind::Box(ref l), &PatKind::Box(ref r)) => self.eq_pat(l, r),
             (&PatKind::TupleStruct(ref lp, ref la, ls), &PatKind::TupleStruct(ref rp, ref ra, rs)) => {
                 self.eq_qpath(lp, rp) && over(la, ra, |l, r| self.eq_pat(l, r)) && ls == rs
             },
-            (&PatKind::Binding(ref lb, _, ref li, ref lp), &PatKind::Binding(ref rb, _, ref ri, ref rp)) => {
+            (&PatKind::Binding(ref lb, .., ref li, ref lp), &PatKind::Binding(ref rb, .., ref ri, ref rp)) => {
                 lb == rb && li.name.as_str() == ri.name.as_str() && both(lp, rp, |l, r| self.eq_pat(l, r))
             },
             (&PatKind::Path(ref l), &PatKind::Path(ref r)) => self.eq_qpath(l, r),
@@ -190,7 +204,8 @@ pub fn eq_pat(&mut self, left: &Pat, right: &Pat) -> bool {
             },
             (&PatKind::Ref(ref le, ref lm), &PatKind::Ref(ref re, ref rm)) => lm == rm && self.eq_pat(le, re),
             (&PatKind::Slice(ref ls, ref li, ref le), &PatKind::Slice(ref rs, ref ri, ref re)) => {
-                over(ls, rs, |l, r| self.eq_pat(l, r)) && over(le, re, |l, r| self.eq_pat(l, r))
+                over(ls, rs, |l, r| self.eq_pat(l, r))
+                    && over(le, re, |l, r| self.eq_pat(l, r))
                     && both(li, ri, |l, r| self.eq_pat(l, r))
             },
             (&PatKind::Wild, &PatKind::Wild) => true,
@@ -198,6 +213,7 @@ pub fn eq_pat(&mut self, left: &Pat, right: &Pat) -> bool {
         }
     }
 
+    #[allow(clippy::similar_names)]
     fn eq_qpath(&mut self, left: &QPath, right: &QPath) -> bool {
         match (left, right) {
             (&QPath::Resolved(ref lty, ref lpath), &QPath::Resolved(ref rty, ref rpath)) => {
@@ -221,11 +237,9 @@ fn eq_path_parameters(&mut self, left: &GenericArgs, right: &GenericArgs) -> boo
                 && over(&left.bindings, &right.bindings, |l, r| self.eq_type_binding(l, r))
         } else if left.parenthesized && right.parenthesized {
             over(left.inputs(), right.inputs(), |l, r| self.eq_ty(l, r))
-                && both(
-                    &Some(&left.bindings[0].ty),
-                    &Some(&right.bindings[0].ty),
-                    |l, r| self.eq_ty(l, r),
-                )
+                && both(&Some(&left.bindings[0].ty), &Some(&right.bindings[0].ty), |l, r| {
+                    self.eq_ty(l, r)
+                })
         } else {
             false
         }
@@ -252,6 +266,7 @@ pub fn eq_ty(&mut self, left: &Ty, right: &Ty) -> bool {
         self.eq_ty_kind(&left.node, &right.node)
     }
 
+    #[allow(clippy::similar_names)]
     pub fn eq_ty_kind(&mut self, left: &TyKind, right: &TyKind) -> bool {
         match (left, right) {
             (&TyKind::Slice(ref l_vec), &TyKind::Slice(ref r_vec)) => self.eq_ty(l_vec, r_vec),
@@ -260,17 +275,19 @@ pub fn eq_ty_kind(&mut self, left: &TyKind, right: &TyKind) -> bool {
 
                 let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id.body));
                 self.tables = self.cx.tcx.body_tables(ll_id.body);
-                let ll = celcx.expr(&self.cx.tcx.hir.body(ll_id.body).value);
+                let ll = celcx.expr(&self.cx.tcx.hir().body(ll_id.body).value);
 
                 let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(rl_id.body));
                 self.tables = self.cx.tcx.body_tables(rl_id.body);
-                let rl = celcx.expr(&self.cx.tcx.hir.body(rl_id.body).value);
+                let rl = celcx.expr(&self.cx.tcx.hir().body(rl_id.body).value);
 
                 let eq_ty = self.eq_ty(lt, rt);
                 self.tables = full_table;
                 eq_ty && ll == rl
             },
-            (&TyKind::Ptr(ref l_mut), &TyKind::Ptr(ref r_mut)) => l_mut.mutbl == r_mut.mutbl && self.eq_ty(&*l_mut.ty, &*r_mut.ty),
+            (&TyKind::Ptr(ref l_mut), &TyKind::Ptr(ref r_mut)) => {
+                l_mut.mutbl == r_mut.mutbl && self.eq_ty(&*l_mut.ty, &*r_mut.ty)
+            },
             (&TyKind::Rptr(_, ref l_rmut), &TyKind::Rptr(_, ref r_rmut)) => {
                 l_rmut.mutbl == r_rmut.mutbl && self.eq_ty(&*l_rmut.ty, &*r_rmut.ty)
             },
@@ -288,28 +305,28 @@ fn eq_type_binding(&mut self, left: &TypeBinding, right: &TypeBinding) -> bool {
 
 fn swap_binop<'a>(binop: BinOpKind, lhs: &'a Expr, rhs: &'a Expr) -> Option<(BinOpKind, &'a Expr, &'a Expr)> {
     match binop {
-        BinOpKind::Add |
-        BinOpKind::Mul |
-        BinOpKind::Eq |
-        BinOpKind::Ne |
-        BinOpKind::BitAnd |
-        BinOpKind::BitXor |
-        BinOpKind::BitOr => Some((binop, rhs, lhs)),
+        BinOpKind::Add
+        | BinOpKind::Mul
+        | BinOpKind::Eq
+        | BinOpKind::Ne
+        | BinOpKind::BitAnd
+        | BinOpKind::BitXor
+        BinOpKind::BitOr => Some((binop, rhs, lhs)),
         BinOpKind::Lt => Some((BinOpKind::Gt, rhs, lhs)),
         BinOpKind::Le => Some((BinOpKind::Ge, rhs, lhs)),
         BinOpKind::Ge => Some((BinOpKind::Le, rhs, lhs)),
         BinOpKind::Gt => Some((BinOpKind::Lt, rhs, lhs)),
-        BinOpKind::Shl |
-        BinOpKind::Shr |
-        BinOpKind::Rem |
-        BinOpKind::Sub |
-        BinOpKind::Div |
-        BinOpKind::And |
-        BinOpKind::Or => None,
+        BinOpKind::Shl
+        | BinOpKind::Shr
+        | BinOpKind::Rem
+        | BinOpKind::Sub
+        | BinOpKind::Div
+        | BinOpKind::And
+        BinOpKind::Or => None,
     }
 }
 
-/// Check if the two `Option`s are both `None` or some equal values as per
+/// Checks if the two `Option`s are both `None` or some equal values as per
 /// `eq_fn`.
 fn both<X, F>(l: &Option<X>, r: &Option<X>, mut eq_fn: F) -> bool
 where
@@ -319,7 +336,7 @@ fn both<X, F>(l: &Option<X>, r: &Option<X>, mut eq_fn: F) -> bool
         .map_or_else(|| r.is_none(), |x| r.as_ref().map_or(false, |y| eq_fn(x, y)))
 }
 
-/// Check if two slices are equal as per `eq_fn`.
+/// Checks if two slices are equal as per `eq_fn`.
 fn over<X, F>(left: &[X], right: &[X], mut eq_fn: F) -> bool
 where
     F: FnMut(&X, &X) -> bool,
@@ -327,7 +344,6 @@ fn over<X, F>(left: &[X], right: &[X], mut eq_fn: F) -> bool
     left.len() == right.len() && left.iter().zip(right).all(|(x, y)| eq_fn(x, y))
 }
 
-
 /// Type used to hash an ast element. This is different from the `Hash` trait
 /// on ast types as this
 /// trait would consider IDs and spans.
@@ -367,62 +383,55 @@ pub fn hash_block(&mut self, b: &Block) {
             BlockCheckMode::UnsafeBlock(_) => 1,
             BlockCheckMode::PushUnsafeBlock(_) => 2,
             BlockCheckMode::PopUnsafeBlock(_) => 3,
-        }.hash(&mut self.s);
+        }
+        .hash(&mut self.s);
     }
 
-    #[allow(clippy::many_single_char_names)]
+    #[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;
-                c.hash(&mut self.s);
                 m.hash(&mut self.s);
                 self.hash_expr(e);
             },
             ExprKind::Continue(i) => {
-                let c: fn(_) -> _ = ExprKind::Continue;
-                c.hash(&mut self.s);
                 if let Some(i) = i.label {
                     self.hash_name(i.ident.name);
                 }
             },
             ExprKind::Yield(ref e) => {
-                let c: fn(_) -> _ = ExprKind::Yield;
-                c.hash(&mut self.s);
                 self.hash_expr(e);
             },
             ExprKind::Assign(ref l, ref r) => {
-                let c: fn(_, _) -> _ = ExprKind::Assign;
-                c.hash(&mut self.s);
                 self.hash_expr(l);
                 self.hash_expr(r);
             },
             ExprKind::AssignOp(ref o, ref l, ref r) => {
-                let c: fn(_, _, _) -> _ = ExprKind::AssignOp;
-                c.hash(&mut self.s);
                 o.hash(&mut self.s);
                 self.hash_expr(l);
                 self.hash_expr(r);
             },
             ExprKind::Block(ref b, _) => {
-                let c: fn(_, _) -> _ = ExprKind::Block;
-                c.hash(&mut self.s);
                 self.hash_block(b);
             },
             ExprKind::Binary(op, ref l, ref r) => {
-                let c: fn(_, _, _) -> _ = ExprKind::Binary;
-                c.hash(&mut self.s);
                 op.node.hash(&mut self.s);
                 self.hash_expr(l);
                 self.hash_expr(r);
             },
             ExprKind::Break(i, ref j) => {
-                let c: fn(_, _) -> _ = ExprKind::Break;
-                c.hash(&mut self.s);
                 if let Some(i) = i.label {
                     self.hash_name(i.ident.name);
                 }
@@ -431,73 +440,43 @@ pub fn hash_expr(&mut self, e: &Expr) {
                 }
             },
             ExprKind::Box(ref e) => {
-                let c: fn(_) -> _ = ExprKind::Box;
-                c.hash(&mut self.s);
                 self.hash_expr(e);
             },
             ExprKind::Call(ref fun, ref args) => {
-                let c: fn(_, _) -> _ = ExprKind::Call;
-                c.hash(&mut self.s);
                 self.hash_expr(fun);
                 self.hash_exprs(args);
             },
             ExprKind::Cast(ref e, ref _ty) => {
-                let c: fn(_, _) -> _ = ExprKind::Cast;
-                c.hash(&mut self.s);
                 self.hash_expr(e);
                 // TODO: _ty
             },
             ExprKind::Closure(cap, _, eid, _, _) => {
-                let c: fn(_, _, _, _, _) -> _ = ExprKind::Closure;
-                c.hash(&mut self.s);
                 match cap {
                     CaptureClause::CaptureByValue => 0,
                     CaptureClause::CaptureByRef => 1,
-                }.hash(&mut self.s);
-                let value = &self.cx.tcx.hir.body(eid).value;
-                self.hash_expr(value);
+                }
+                .hash(&mut self.s);
+                self.hash_expr(&self.cx.tcx.hir().body(eid).value);
             },
             ExprKind::Field(ref e, ref f) => {
-                let c: fn(_, _) -> _ = ExprKind::Field;
-                c.hash(&mut self.s);
                 self.hash_expr(e);
                 self.hash_name(f.name);
             },
             ExprKind::Index(ref a, ref i) => {
-                let c: fn(_, _) -> _ = ExprKind::Index;
-                c.hash(&mut self.s);
                 self.hash_expr(a);
                 self.hash_expr(i);
             },
-            ExprKind::InlineAsm(..) => {
-                let c: fn(_, _, _) -> _ = ExprKind::InlineAsm;
-                c.hash(&mut self.s);
-            },
-            ExprKind::If(ref cond, ref t, ref e) => {
-                let c: fn(_, _, _) -> _ = ExprKind::If;
-                c.hash(&mut self.s);
-                self.hash_expr(cond);
-                self.hash_expr(&**t);
-                if let Some(ref e) = *e {
-                    self.hash_expr(e);
-                }
-            },
+            ExprKind::InlineAsm(..) => {},
             ExprKind::Lit(ref l) => {
-                let c: fn(_) -> _ = ExprKind::Lit;
-                c.hash(&mut self.s);
                 l.hash(&mut self.s);
             },
             ExprKind::Loop(ref b, ref i, _) => {
-                let c: fn(_, _, _) -> _ = ExprKind::Loop;
-                c.hash(&mut self.s);
                 self.hash_block(b);
                 if let Some(i) = *i {
                     self.hash_name(i.ident.name);
                 }
             },
             ExprKind::Match(ref e, ref arms, ref s) => {
-                let c: fn(_, _, _) -> _ = ExprKind::Match;
-                c.hash(&mut self.s);
                 self.hash_expr(e);
 
                 for arm in arms {
@@ -511,37 +490,25 @@ pub fn hash_expr(&mut self, e: &Expr) {
                 s.hash(&mut self.s);
             },
             ExprKind::MethodCall(ref path, ref _tys, ref args) => {
-                let c: fn(_, _, _) -> _ = ExprKind::MethodCall;
-                c.hash(&mut self.s);
                 self.hash_name(path.ident.name);
                 self.hash_exprs(args);
             },
             ExprKind::Repeat(ref e, ref l_id) => {
-                let c: fn(_, _) -> _ = ExprKind::Repeat;
-                c.hash(&mut self.s);
                 self.hash_expr(e);
                 let full_table = self.tables;
                 self.tables = self.cx.tcx.body_tables(l_id.body);
-                let value = &self.cx.tcx.hir.body(l_id.body).value;
-                self.hash_expr(value);
+                self.hash_expr(&self.cx.tcx.hir().body(l_id.body).value);
                 self.tables = full_table;
             },
             ExprKind::Ret(ref e) => {
-                let c: fn(_) -> _ = ExprKind::Ret;
-                c.hash(&mut self.s);
                 if let Some(ref e) = *e {
                     self.hash_expr(e);
                 }
             },
             ExprKind::Path(ref qpath) => {
-                let c: fn(_) -> _ = ExprKind::Path;
-                c.hash(&mut self.s);
                 self.hash_qpath(qpath);
             },
             ExprKind::Struct(ref path, ref fields, ref expr) => {
-                let c: fn(_, _, _) -> _ = ExprKind::Struct;
-                c.hash(&mut self.s);
-
                 self.hash_qpath(path);
 
                 for f in fields {
@@ -554,39 +521,30 @@ pub fn hash_expr(&mut self, e: &Expr) {
                 }
             },
             ExprKind::Tup(ref tup) => {
-                let c: fn(_) -> _ = ExprKind::Tup;
-                c.hash(&mut self.s);
                 self.hash_exprs(tup);
             },
             ExprKind::Type(ref e, ref _ty) => {
-                let c: fn(_, _) -> _ = ExprKind::Type;
-                c.hash(&mut self.s);
                 self.hash_expr(e);
                 // TODO: _ty
             },
             ExprKind::Unary(lop, ref le) => {
-                let c: fn(_, _) -> _ = ExprKind::Unary;
-                c.hash(&mut self.s);
-
                 lop.hash(&mut self.s);
                 self.hash_expr(le);
             },
             ExprKind::Array(ref v) => {
-                let c: fn(_) -> _ = ExprKind::Array;
-                c.hash(&mut self.s);
-
                 self.hash_exprs(v);
             },
             ExprKind::While(ref cond, ref b, l) => {
-                let c: fn(_, _, _) -> _ = ExprKind::While;
-                c.hash(&mut self.s);
-
                 self.hash_expr(cond);
                 self.hash_block(b);
                 if let Some(l) = l {
                     self.hash_name(l.ident.name);
                 }
             },
+            ExprKind::Err => {},
+            ExprKind::DropTemps(ref e) => {
+                self.hash_expr(e);
+            },
         }
     }
 
@@ -609,7 +567,7 @@ pub fn hash_qpath(&mut self, p: &QPath) {
                 self.hash_name(path.ident.name);
             },
         }
-        // self.cx.tables.qpath_def(p, id).hash(&mut self.s);
+        // self.cx.tables.qpath_res(p, id).hash(&mut self.s);
     }
 
     pub fn hash_path(&mut self, p: &Path) {
@@ -620,25 +578,19 @@ pub fn hash_path(&mut self, p: &Path) {
     }
 
     pub fn hash_stmt(&mut self, b: &Stmt) {
-        match b.node {
-            StmtKind::Decl(ref decl, _) => {
-                let c: fn(_, _) -> _ = StmtKind::Decl;
-                c.hash(&mut self.s);
+        std::mem::discriminant(&b.node).hash(&mut self.s);
 
-                if let DeclKind::Local(ref local) = decl.node {
-                    if let Some(ref init) = local.init {
-                        self.hash_expr(init);
-                    }
+        match b.node {
+            StmtKind::Local(ref local) => {
+                if let Some(ref init) = local.init {
+                    self.hash_expr(init);
                 }
             },
-            StmtKind::Expr(ref expr, _) => {
-                let c: fn(_, _) -> _ = StmtKind::Expr;
-                c.hash(&mut self.s);
+            StmtKind::Item(..) => {},
+            StmtKind::Expr(ref expr) => {
                 self.hash_expr(expr);
             },
-            StmtKind::Semi(ref expr, _) => {
-                let c: fn(_, _) -> _ = StmtKind::Semi;
-                c.hash(&mut self.s);
+            StmtKind::Semi(ref expr) => {
                 self.hash_expr(expr);
             },
         }
@@ -647,10 +599,8 @@ pub fn hash_stmt(&mut self, b: &Stmt) {
     pub fn hash_guard(&mut self, g: &Guard) {
         match g {
             Guard::If(ref expr) => {
-                let c: fn(_) -> _ = Guard::If;
-                c.hash(&mut self.s);
                 self.hash_expr(expr);
-            }
+            },
         }
     }
 }