From 9a3f53dee69ee5691012953870777d332401d0ce Mon Sep 17 00:00:00 2001 From: mcarton Date: Sun, 2 Oct 2016 02:17:04 +0200 Subject: [PATCH] Partially hash `let` declaration in `SpanlessHash` The hash never needs to be good but before it was simply doing nothing for these. --- clippy_lints/src/utils/hir.rs | 9 +++++++-- tests/compile-fail/copies.rs | 35 +++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/clippy_lints/src/utils/hir.rs b/clippy_lints/src/utils/hir.rs index fd954d1969f..bb9d0583ab1 100644 --- a/clippy_lints/src/utils/hir.rs +++ b/clippy_lints/src/utils/hir.rs @@ -528,10 +528,15 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> { pub fn hash_stmt(&mut self, b: &Stmt) { match b.node { - StmtDecl(ref _decl, _) => { + StmtDecl(ref decl, _) => { let c: fn(_, _) -> _ = StmtDecl; c.hash(&mut self.s); - // TODO: decl + + if let DeclLocal(ref local) = decl.node { + if let Some(ref init) = local.init { + self.hash_expr(init); + } + } } StmtExpr(ref expr, _) => { let c: fn(_, _) -> _ = StmtExpr; diff --git a/tests/compile-fail/copies.rs b/tests/compile-fail/copies.rs index c84c1062072..dba653a148f 100644 --- a/tests/compile-fail/copies.rs +++ b/tests/compile-fail/copies.rs @@ -70,20 +70,27 @@ fn if_same_then_else() -> Result<&'static str, ()> { foo(); } - let _ = if true { - //~^NOTE same as this - foo(); - let mut a = 42 + [23].len() as i32; - a += 7; - a = -31-a; - a - } - else { //~ERROR this `if` has identical blocks - foo(); - let mut a = 42 + [23].len() as i32; - a += 7; - a = -31-a; - a + let _ = match 42 { + 42 => { + //~^ NOTE same as this + //~| NOTE refactoring + foo(); + let mut a = 42 + [23].len() as i32; + if true { + a += 7; + } + a = -31-a; + a + } + _ => { //~ERROR this `match` has identical arm bodies + foo(); + let mut a = 42 + [23].len() as i32; + if true { + a += 7; + } + a = -31-a; + a + } }; if true {