1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 use crate::consts::{constant_context, constant_simple};
11 use crate::rustc::hir::*;
12 use crate::rustc::lint::LateContext;
13 use crate::rustc::ty::TypeckTables;
14 use crate::syntax::ast::Name;
15 use crate::syntax::ptr::P;
16 use crate::utils::differing_macro_contexts;
17 use std::collections::hash_map::DefaultHasher;
18 use std::hash::{Hash, Hasher};
20 /// Type used to check whether two ast are the same. This is different from the
22 /// `==` on ast types as this operator would compare true equality with ID and
25 /// Note that some expressions kinds are not considered but could be added.
26 pub struct SpanlessEq<'a, 'tcx: 'a> {
27 /// Context used to evaluate constant expressions.
28 cx: &'a LateContext<'a, 'tcx>,
29 tables: &'a TypeckTables<'tcx>,
30 /// If is true, never consider as equal expressions containing function
35 impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
36 pub fn new(cx: &'a LateContext<'a, 'tcx>) -> Self {
44 pub fn ignore_fn(self) -> Self {
47 tables: self.cx.tables,
52 /// Check whether two statements are the same.
53 pub fn eq_stmt(&mut self, left: &Stmt, right: &Stmt) -> bool {
54 match (&left.node, &right.node) {
55 (&StmtKind::Decl(ref l, _), &StmtKind::Decl(ref r, _)) => {
56 if let (&DeclKind::Local(ref l), &DeclKind::Local(ref r)) = (&l.node, &r.node) {
57 both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r)) && both(&l.init, &r.init, |l, r| self.eq_expr(l, r))
62 (&StmtKind::Expr(ref l, _), &StmtKind::Expr(ref r, _))
63 | (&StmtKind::Semi(ref l, _), &StmtKind::Semi(ref r, _)) => self.eq_expr(l, r),
68 /// Check whether two blocks are the same.
69 pub fn eq_block(&mut self, left: &Block, right: &Block) -> bool {
70 over(&left.stmts, &right.stmts, |l, r| self.eq_stmt(l, r))
71 && both(&left.expr, &right.expr, |l, r| self.eq_expr(l, r))
74 #[allow(clippy::similar_names)]
75 pub fn eq_expr(&mut self, left: &Expr, right: &Expr) -> bool {
76 if self.ignore_fn && differing_macro_contexts(left.span, right.span) {
80 if let (Some(l), Some(r)) = (
81 constant_simple(self.cx, self.tables, left),
82 constant_simple(self.cx, self.tables, right),
89 match (&left.node, &right.node) {
90 (&ExprKind::AddrOf(l_mut, ref le), &ExprKind::AddrOf(r_mut, ref re)) => {
91 l_mut == r_mut && self.eq_expr(le, re)
93 (&ExprKind::Continue(li), &ExprKind::Continue(ri)) => {
94 both(&li.label, &ri.label, |l, r| l.ident.as_str() == r.ident.as_str())
96 (&ExprKind::Assign(ref ll, ref lr), &ExprKind::Assign(ref rl, ref rr)) => {
97 self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
99 (&ExprKind::AssignOp(ref lo, ref ll, ref lr), &ExprKind::AssignOp(ref ro, ref rl, ref rr)) => {
100 lo.node == ro.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
102 (&ExprKind::Block(ref l, _), &ExprKind::Block(ref r, _)) => self.eq_block(l, r),
103 (&ExprKind::Binary(l_op, ref ll, ref lr), &ExprKind::Binary(r_op, ref rl, ref rr)) => {
104 l_op.node == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
105 || swap_binop(l_op.node, ll, lr).map_or(false, |(l_op, ll, lr)| {
106 l_op == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
109 (&ExprKind::Break(li, ref le), &ExprKind::Break(ri, ref re)) => {
110 both(&li.label, &ri.label, |l, r| l.ident.as_str() == r.ident.as_str())
111 && both(le, re, |l, r| self.eq_expr(l, r))
113 (&ExprKind::Box(ref l), &ExprKind::Box(ref r)) => self.eq_expr(l, r),
114 (&ExprKind::Call(ref l_fun, ref l_args), &ExprKind::Call(ref r_fun, ref r_args)) => {
115 !self.ignore_fn && self.eq_expr(l_fun, r_fun) && self.eq_exprs(l_args, r_args)
117 (&ExprKind::Cast(ref lx, ref lt), &ExprKind::Cast(ref rx, ref rt))
118 | (&ExprKind::Type(ref lx, ref lt), &ExprKind::Type(ref rx, ref rt)) => {
119 self.eq_expr(lx, rx) && self.eq_ty(lt, rt)
121 (&ExprKind::Field(ref l_f_exp, ref l_f_ident), &ExprKind::Field(ref r_f_exp, ref r_f_ident)) => {
122 l_f_ident.name == r_f_ident.name && self.eq_expr(l_f_exp, r_f_exp)
124 (&ExprKind::Index(ref la, ref li), &ExprKind::Index(ref ra, ref ri)) => {
125 self.eq_expr(la, ra) && self.eq_expr(li, ri)
127 (&ExprKind::If(ref lc, ref lt, ref le), &ExprKind::If(ref rc, ref rt, ref re)) => {
128 self.eq_expr(lc, rc) && self.eq_expr(&**lt, &**rt) && both(le, re, |l, r| self.eq_expr(l, r))
130 (&ExprKind::Lit(ref l), &ExprKind::Lit(ref r)) => l.node == r.node,
131 (&ExprKind::Loop(ref lb, ref ll, ref lls), &ExprKind::Loop(ref rb, ref rl, ref rls)) => {
132 lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.as_str() == r.ident.as_str())
134 (&ExprKind::Match(ref le, ref la, ref ls), &ExprKind::Match(ref re, ref ra, ref rs)) => {
136 && self.eq_expr(le, re)
137 && over(la, ra, |l, r| {
138 self.eq_expr(&l.body, &r.body)
139 && both(&l.guard, &r.guard, |l, r| self.eq_guard(l, r))
140 && over(&l.pats, &r.pats, |l, r| self.eq_pat(l, r))
143 (&ExprKind::MethodCall(ref l_path, _, ref l_args), &ExprKind::MethodCall(ref r_path, _, ref r_args)) => {
144 !self.ignore_fn && self.eq_path_segment(l_path, r_path) && self.eq_exprs(l_args, r_args)
146 (&ExprKind::Repeat(ref le, ref ll_id), &ExprKind::Repeat(ref re, ref rl_id)) => {
147 let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id.body));
148 let ll = celcx.expr(&self.cx.tcx.hir().body(ll_id.body).value);
149 let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(rl_id.body));
150 let rl = celcx.expr(&self.cx.tcx.hir().body(rl_id.body).value);
152 self.eq_expr(le, re) && ll == rl
154 (&ExprKind::Ret(ref l), &ExprKind::Ret(ref r)) => both(l, r, |l, r| self.eq_expr(l, r)),
155 (&ExprKind::Path(ref l), &ExprKind::Path(ref r)) => self.eq_qpath(l, r),
156 (&ExprKind::Struct(ref l_path, ref lf, ref lo), &ExprKind::Struct(ref r_path, ref rf, ref ro)) => {
157 self.eq_qpath(l_path, r_path)
158 && both(lo, ro, |l, r| self.eq_expr(l, r))
159 && over(lf, rf, |l, r| self.eq_field(l, r))
161 (&ExprKind::Tup(ref l_tup), &ExprKind::Tup(ref r_tup)) => self.eq_exprs(l_tup, r_tup),
162 (&ExprKind::Unary(l_op, ref le), &ExprKind::Unary(r_op, ref re)) => l_op == r_op && self.eq_expr(le, re),
163 (&ExprKind::Array(ref l), &ExprKind::Array(ref r)) => self.eq_exprs(l, r),
164 (&ExprKind::While(ref lc, ref lb, ref ll), &ExprKind::While(ref rc, ref rb, ref rl)) => {
166 && self.eq_block(lb, rb)
167 && both(ll, rl, |l, r| l.ident.as_str() == r.ident.as_str())
173 fn eq_exprs(&mut self, left: &P<[Expr]>, right: &P<[Expr]>) -> bool {
174 over(left, right, |l, r| self.eq_expr(l, r))
177 fn eq_field(&mut self, left: &Field, right: &Field) -> bool {
178 left.ident.name == right.ident.name && self.eq_expr(&left.expr, &right.expr)
181 fn eq_guard(&mut self, left: &Guard, right: &Guard) -> bool {
182 match (left, right) {
183 (Guard::If(l), Guard::If(r)) => self.eq_expr(l, r),
187 fn eq_generic_arg(&mut self, left: &GenericArg, right: &GenericArg) -> bool {
188 match (left, right) {
189 (GenericArg::Lifetime(l_lt), GenericArg::Lifetime(r_lt)) => self.eq_lifetime(l_lt, r_lt),
190 (GenericArg::Type(l_ty), GenericArg::Type(r_ty)) => self.eq_ty(l_ty, r_ty),
195 fn eq_lifetime(&mut self, left: &Lifetime, right: &Lifetime) -> bool {
196 left.name == right.name
199 /// Check whether two patterns are the same.
200 pub fn eq_pat(&mut self, left: &Pat, right: &Pat) -> bool {
201 match (&left.node, &right.node) {
202 (&PatKind::Box(ref l), &PatKind::Box(ref r)) => self.eq_pat(l, r),
203 (&PatKind::TupleStruct(ref lp, ref la, ls), &PatKind::TupleStruct(ref rp, ref ra, rs)) => {
204 self.eq_qpath(lp, rp) && over(la, ra, |l, r| self.eq_pat(l, r)) && ls == rs
206 (&PatKind::Binding(ref lb, _, ref li, ref lp), &PatKind::Binding(ref rb, _, ref ri, ref rp)) => {
207 lb == rb && li.name.as_str() == ri.name.as_str() && both(lp, rp, |l, r| self.eq_pat(l, r))
209 (&PatKind::Path(ref l), &PatKind::Path(ref r)) => self.eq_qpath(l, r),
210 (&PatKind::Lit(ref l), &PatKind::Lit(ref r)) => self.eq_expr(l, r),
211 (&PatKind::Tuple(ref l, ls), &PatKind::Tuple(ref r, rs)) => {
212 ls == rs && over(l, r, |l, r| self.eq_pat(l, r))
214 (&PatKind::Range(ref ls, ref le, ref li), &PatKind::Range(ref rs, ref re, ref ri)) => {
215 self.eq_expr(ls, rs) && self.eq_expr(le, re) && (*li == *ri)
217 (&PatKind::Ref(ref le, ref lm), &PatKind::Ref(ref re, ref rm)) => lm == rm && self.eq_pat(le, re),
218 (&PatKind::Slice(ref ls, ref li, ref le), &PatKind::Slice(ref rs, ref ri, ref re)) => {
219 over(ls, rs, |l, r| self.eq_pat(l, r))
220 && over(le, re, |l, r| self.eq_pat(l, r))
221 && both(li, ri, |l, r| self.eq_pat(l, r))
223 (&PatKind::Wild, &PatKind::Wild) => true,
228 #[allow(clippy::similar_names)]
229 fn eq_qpath(&mut self, left: &QPath, right: &QPath) -> bool {
230 match (left, right) {
231 (&QPath::Resolved(ref lty, ref lpath), &QPath::Resolved(ref rty, ref rpath)) => {
232 both(lty, rty, |l, r| self.eq_ty(l, r)) && self.eq_path(lpath, rpath)
234 (&QPath::TypeRelative(ref lty, ref lseg), &QPath::TypeRelative(ref rty, ref rseg)) => {
235 self.eq_ty(lty, rty) && self.eq_path_segment(lseg, rseg)
241 fn eq_path(&mut self, left: &Path, right: &Path) -> bool {
242 left.is_global() == right.is_global()
243 && over(&left.segments, &right.segments, |l, r| self.eq_path_segment(l, r))
246 fn eq_path_parameters(&mut self, left: &GenericArgs, right: &GenericArgs) -> bool {
247 if !(left.parenthesized || right.parenthesized) {
248 over(&left.args, &right.args, |l, r| self.eq_generic_arg(l, r)) // FIXME(flip1995): may not work
249 && over(&left.bindings, &right.bindings, |l, r| self.eq_type_binding(l, r))
250 } else if left.parenthesized && right.parenthesized {
251 over(left.inputs(), right.inputs(), |l, r| self.eq_ty(l, r))
252 && both(&Some(&left.bindings[0].ty), &Some(&right.bindings[0].ty), |l, r| {
260 pub fn eq_path_segments(&mut self, left: &[PathSegment], right: &[PathSegment]) -> bool {
261 left.len() == right.len() && left.iter().zip(right).all(|(l, r)| self.eq_path_segment(l, r))
264 pub fn eq_path_segment(&mut self, left: &PathSegment, right: &PathSegment) -> bool {
265 // The == of idents doesn't work with different contexts,
266 // we have to be explicit about hygiene
267 if left.ident.as_str() != right.ident.as_str() {
270 match (&left.args, &right.args) {
271 (&None, &None) => true,
272 (&Some(ref l), &Some(ref r)) => self.eq_path_parameters(l, r),
277 pub fn eq_ty(&mut self, left: &Ty, right: &Ty) -> bool {
278 self.eq_ty_kind(&left.node, &right.node)
281 #[allow(clippy::similar_names)]
282 pub fn eq_ty_kind(&mut self, left: &TyKind, right: &TyKind) -> bool {
283 match (left, right) {
284 (&TyKind::Slice(ref l_vec), &TyKind::Slice(ref r_vec)) => self.eq_ty(l_vec, r_vec),
285 (&TyKind::Array(ref lt, ref ll_id), &TyKind::Array(ref rt, ref rl_id)) => {
286 let full_table = self.tables;
288 let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id.body));
289 self.tables = self.cx.tcx.body_tables(ll_id.body);
290 let ll = celcx.expr(&self.cx.tcx.hir().body(ll_id.body).value);
292 let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(rl_id.body));
293 self.tables = self.cx.tcx.body_tables(rl_id.body);
294 let rl = celcx.expr(&self.cx.tcx.hir().body(rl_id.body).value);
296 let eq_ty = self.eq_ty(lt, rt);
297 self.tables = full_table;
300 (&TyKind::Ptr(ref l_mut), &TyKind::Ptr(ref r_mut)) => {
301 l_mut.mutbl == r_mut.mutbl && self.eq_ty(&*l_mut.ty, &*r_mut.ty)
303 (&TyKind::Rptr(_, ref l_rmut), &TyKind::Rptr(_, ref r_rmut)) => {
304 l_rmut.mutbl == r_rmut.mutbl && self.eq_ty(&*l_rmut.ty, &*r_rmut.ty)
306 (&TyKind::Path(ref l), &TyKind::Path(ref r)) => self.eq_qpath(l, r),
307 (&TyKind::Tup(ref l), &TyKind::Tup(ref r)) => over(l, r, |l, r| self.eq_ty(l, r)),
308 (&TyKind::Infer, &TyKind::Infer) => true,
313 fn eq_type_binding(&mut self, left: &TypeBinding, right: &TypeBinding) -> bool {
314 left.ident.name == right.ident.name && self.eq_ty(&left.ty, &right.ty)
318 fn swap_binop<'a>(binop: BinOpKind, lhs: &'a Expr, rhs: &'a Expr) -> Option<(BinOpKind, &'a Expr, &'a Expr)> {
326 | BinOpKind::BitOr => Some((binop, rhs, lhs)),
327 BinOpKind::Lt => Some((BinOpKind::Gt, rhs, lhs)),
328 BinOpKind::Le => Some((BinOpKind::Ge, rhs, lhs)),
329 BinOpKind::Ge => Some((BinOpKind::Le, rhs, lhs)),
330 BinOpKind::Gt => Some((BinOpKind::Lt, rhs, lhs)),
337 | BinOpKind::Or => None,
341 /// Check if the two `Option`s are both `None` or some equal values as per
343 fn both<X, F>(l: &Option<X>, r: &Option<X>, mut eq_fn: F) -> bool
345 F: FnMut(&X, &X) -> bool,
348 .map_or_else(|| r.is_none(), |x| r.as_ref().map_or(false, |y| eq_fn(x, y)))
351 /// Check if two slices are equal as per `eq_fn`.
352 fn over<X, F>(left: &[X], right: &[X], mut eq_fn: F) -> bool
354 F: FnMut(&X, &X) -> bool,
356 left.len() == right.len() && left.iter().zip(right).all(|(x, y)| eq_fn(x, y))
359 /// Type used to hash an ast element. This is different from the `Hash` trait
360 /// on ast types as this
361 /// trait would consider IDs and spans.
363 /// All expressions kind are hashed, but some might have a weaker hash.
364 pub struct SpanlessHash<'a, 'tcx: 'a> {
365 /// Context used to evaluate constant expressions.
366 cx: &'a LateContext<'a, 'tcx>,
367 tables: &'a TypeckTables<'tcx>,
371 impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
372 pub fn new(cx: &'a LateContext<'a, 'tcx>, tables: &'a TypeckTables<'tcx>) -> Self {
376 s: DefaultHasher::new(),
380 pub fn finish(&self) -> u64 {
384 pub fn hash_block(&mut self, b: &Block) {
389 if let Some(ref e) = b.expr {
394 BlockCheckMode::DefaultBlock => 0,
395 BlockCheckMode::UnsafeBlock(_) => 1,
396 BlockCheckMode::PushUnsafeBlock(_) => 2,
397 BlockCheckMode::PopUnsafeBlock(_) => 3,
402 #[allow(clippy::many_single_char_names)]
403 pub fn hash_expr(&mut self, e: &Expr) {
404 if let Some(e) = constant_simple(self.cx, self.tables, e) {
405 return e.hash(&mut self.s);
409 ExprKind::AddrOf(m, ref e) => {
410 let c: fn(_, _) -> _ = ExprKind::AddrOf;
415 ExprKind::Continue(i) => {
416 let c: fn(_) -> _ = ExprKind::Continue;
418 if let Some(i) = i.label {
419 self.hash_name(i.ident.name);
422 ExprKind::Yield(ref e) => {
423 let c: fn(_) -> _ = ExprKind::Yield;
427 ExprKind::Assign(ref l, ref r) => {
428 let c: fn(_, _) -> _ = ExprKind::Assign;
433 ExprKind::AssignOp(ref o, ref l, ref r) => {
434 let c: fn(_, _, _) -> _ = ExprKind::AssignOp;
440 ExprKind::Block(ref b, _) => {
441 let c: fn(_, _) -> _ = ExprKind::Block;
445 ExprKind::Binary(op, ref l, ref r) => {
446 let c: fn(_, _, _) -> _ = ExprKind::Binary;
448 op.node.hash(&mut self.s);
452 ExprKind::Break(i, ref j) => {
453 let c: fn(_, _) -> _ = ExprKind::Break;
455 if let Some(i) = i.label {
456 self.hash_name(i.ident.name);
458 if let Some(ref j) = *j {
462 ExprKind::Box(ref e) => {
463 let c: fn(_) -> _ = ExprKind::Box;
467 ExprKind::Call(ref fun, ref args) => {
468 let c: fn(_, _) -> _ = ExprKind::Call;
471 self.hash_exprs(args);
473 ExprKind::Cast(ref e, ref _ty) => {
474 let c: fn(_, _) -> _ = ExprKind::Cast;
479 ExprKind::Closure(cap, _, eid, _, _) => {
480 let c: fn(_, _, _, _, _) -> _ = ExprKind::Closure;
483 CaptureClause::CaptureByValue => 0,
484 CaptureClause::CaptureByRef => 1,
487 self.hash_expr(&self.cx.tcx.hir().body(eid).value);
489 ExprKind::Field(ref e, ref f) => {
490 let c: fn(_, _) -> _ = ExprKind::Field;
493 self.hash_name(f.name);
495 ExprKind::Index(ref a, ref i) => {
496 let c: fn(_, _) -> _ = ExprKind::Index;
501 ExprKind::InlineAsm(..) => {
502 let c: fn(_, _, _) -> _ = ExprKind::InlineAsm;
505 ExprKind::If(ref cond, ref t, ref e) => {
506 let c: fn(_, _, _) -> _ = ExprKind::If;
508 self.hash_expr(cond);
509 self.hash_expr(&**t);
510 if let Some(ref e) = *e {
514 ExprKind::Lit(ref l) => {
515 let c: fn(_) -> _ = ExprKind::Lit;
519 ExprKind::Loop(ref b, ref i, _) => {
520 let c: fn(_, _, _) -> _ = ExprKind::Loop;
523 if let Some(i) = *i {
524 self.hash_name(i.ident.name);
527 ExprKind::Match(ref e, ref arms, ref s) => {
528 let c: fn(_, _, _) -> _ = ExprKind::Match;
534 if let Some(ref e) = arm.guard {
537 self.hash_expr(&arm.body);
542 ExprKind::MethodCall(ref path, ref _tys, ref args) => {
543 let c: fn(_, _, _) -> _ = ExprKind::MethodCall;
545 self.hash_name(path.ident.name);
546 self.hash_exprs(args);
548 ExprKind::Repeat(ref e, ref l_id) => {
549 let c: fn(_, _) -> _ = ExprKind::Repeat;
552 let full_table = self.tables;
553 self.tables = self.cx.tcx.body_tables(l_id.body);
554 self.hash_expr(&self.cx.tcx.hir().body(l_id.body).value);
555 self.tables = full_table;
557 ExprKind::Ret(ref e) => {
558 let c: fn(_) -> _ = ExprKind::Ret;
560 if let Some(ref e) = *e {
564 ExprKind::Path(ref qpath) => {
565 let c: fn(_) -> _ = ExprKind::Path;
567 self.hash_qpath(qpath);
569 ExprKind::Struct(ref path, ref fields, ref expr) => {
570 let c: fn(_, _, _) -> _ = ExprKind::Struct;
573 self.hash_qpath(path);
576 self.hash_name(f.ident.name);
577 self.hash_expr(&f.expr);
580 if let Some(ref e) = *expr {
584 ExprKind::Tup(ref tup) => {
585 let c: fn(_) -> _ = ExprKind::Tup;
587 self.hash_exprs(tup);
589 ExprKind::Type(ref e, ref _ty) => {
590 let c: fn(_, _) -> _ = ExprKind::Type;
595 ExprKind::Unary(lop, ref le) => {
596 let c: fn(_, _) -> _ = ExprKind::Unary;
599 lop.hash(&mut self.s);
602 ExprKind::Array(ref v) => {
603 let c: fn(_) -> _ = ExprKind::Array;
608 ExprKind::While(ref cond, ref b, l) => {
609 let c: fn(_, _, _) -> _ = ExprKind::While;
612 self.hash_expr(cond);
615 self.hash_name(l.ident.name);
621 pub fn hash_exprs(&mut self, e: &P<[Expr]>) {
627 pub fn hash_name(&mut self, n: Name) {
628 n.as_str().hash(&mut self.s);
631 pub fn hash_qpath(&mut self, p: &QPath) {
633 QPath::Resolved(_, ref path) => {
634 self.hash_path(path);
636 QPath::TypeRelative(_, ref path) => {
637 self.hash_name(path.ident.name);
640 // self.cx.tables.qpath_def(p, id).hash(&mut self.s);
643 pub fn hash_path(&mut self, p: &Path) {
644 p.is_global().hash(&mut self.s);
645 for p in &p.segments {
646 self.hash_name(p.ident.name);
650 pub fn hash_stmt(&mut self, b: &Stmt) {
652 StmtKind::Decl(ref decl, _) => {
653 let c: fn(_, _) -> _ = StmtKind::Decl;
656 if let DeclKind::Local(ref local) = decl.node {
657 if let Some(ref init) = local.init {
658 self.hash_expr(init);
662 StmtKind::Expr(ref expr, _) => {
663 let c: fn(_, _) -> _ = StmtKind::Expr;
665 self.hash_expr(expr);
667 StmtKind::Semi(ref expr, _) => {
668 let c: fn(_, _) -> _ = StmtKind::Semi;
670 self.hash_expr(expr);
675 pub fn hash_guard(&mut self, g: &Guard) {
677 Guard::If(ref expr) => {
678 let c: fn(_) -> _ = Guard::If;
680 self.hash_expr(expr);