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.
11 use crate::consts::{constant_simple, constant_context};
12 use crate::rustc::lint::LateContext;
13 use crate::rustc::hir::*;
14 use crate::rustc::ty::{TypeckTables};
15 use std::hash::{Hash, Hasher};
16 use std::collections::hash_map::DefaultHasher;
17 use crate::syntax::ast::Name;
18 use crate::syntax::ptr::P;
19 use crate::utils::differing_macro_contexts;
21 /// Type used to check whether two ast are the same. This is different from the
23 /// `==` on ast types as this operator would compare true equality with ID and
26 /// Note that some expressions kinds are not considered but could be added.
27 pub struct SpanlessEq<'a, 'tcx: 'a> {
28 /// Context used to evaluate constant expressions.
29 cx: &'a LateContext<'a, 'tcx>,
30 tables: &'a TypeckTables<'tcx>,
31 /// If is true, never consider as equal expressions containing function
36 impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
37 pub fn new(cx: &'a LateContext<'a, 'tcx>) -> Self {
45 pub fn ignore_fn(self) -> Self {
48 tables: self.cx.tables,
53 /// Check whether two statements are the same.
54 pub fn eq_stmt(&mut self, left: &Stmt, right: &Stmt) -> bool {
55 match (&left.node, &right.node) {
56 (&StmtKind::Decl(ref l, _), &StmtKind::Decl(ref r, _)) => {
57 if let (&DeclKind::Local(ref l), &DeclKind::Local(ref r)) = (&l.node, &r.node) {
58 both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r)) && both(&l.init, &r.init, |l, r| self.eq_expr(l, r))
63 (&StmtKind::Expr(ref l, _), &StmtKind::Expr(ref r, _)) | (&StmtKind::Semi(ref l, _), &StmtKind::Semi(ref r, _)) => {
70 /// Check whether two blocks are the same.
71 pub fn eq_block(&mut self, left: &Block, right: &Block) -> bool {
72 over(&left.stmts, &right.stmts, |l, r| self.eq_stmt(l, r))
73 && both(&left.expr, &right.expr, |l, r| self.eq_expr(l, r))
76 #[allow(clippy::similar_names)]
77 pub fn eq_expr(&mut self, left: &Expr, right: &Expr) -> bool {
78 if self.ignore_fn && differing_macro_contexts(left.span, right.span) {
82 if let (Some(l), Some(r)) = (constant_simple(self.cx, self.tables, left), constant_simple(self.cx, self.tables, right)) {
88 match (&left.node, &right.node) {
89 (&ExprKind::AddrOf(l_mut, ref le), &ExprKind::AddrOf(r_mut, ref re)) => l_mut == r_mut && self.eq_expr(le, re),
90 (&ExprKind::Continue(li), &ExprKind::Continue(ri)) => {
91 both(&li.label, &ri.label, |l, r| l.ident.as_str() == r.ident.as_str())
93 (&ExprKind::Assign(ref ll, ref lr), &ExprKind::Assign(ref rl, ref rr)) => self.eq_expr(ll, rl) && self.eq_expr(lr, rr),
94 (&ExprKind::AssignOp(ref lo, ref ll, ref lr), &ExprKind::AssignOp(ref ro, ref rl, ref rr)) => {
95 lo.node == ro.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
97 (&ExprKind::Block(ref l, _), &ExprKind::Block(ref r, _)) => self.eq_block(l, r),
98 (&ExprKind::Binary(l_op, ref ll, ref lr), &ExprKind::Binary(r_op, ref rl, ref rr)) => {
99 l_op.node == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
100 || swap_binop(l_op.node, ll, lr).map_or(false, |(l_op, ll, lr)| {
101 l_op == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
104 (&ExprKind::Break(li, ref le), &ExprKind::Break(ri, ref re)) => {
105 both(&li.label, &ri.label, |l, r| l.ident.as_str() == r.ident.as_str())
106 && both(le, re, |l, r| self.eq_expr(l, r))
108 (&ExprKind::Box(ref l), &ExprKind::Box(ref r)) => self.eq_expr(l, r),
109 (&ExprKind::Call(ref l_fun, ref l_args), &ExprKind::Call(ref r_fun, ref r_args)) => {
110 !self.ignore_fn && self.eq_expr(l_fun, r_fun) && self.eq_exprs(l_args, r_args)
112 (&ExprKind::Cast(ref lx, ref lt), &ExprKind::Cast(ref rx, ref rt)) |
113 (&ExprKind::Type(ref lx, ref lt), &ExprKind::Type(ref rx, ref rt)) => self.eq_expr(lx, rx) && self.eq_ty(lt, rt),
114 (&ExprKind::Field(ref l_f_exp, ref l_f_ident), &ExprKind::Field(ref r_f_exp, ref r_f_ident)) => {
115 l_f_ident.name == r_f_ident.name && self.eq_expr(l_f_exp, r_f_exp)
117 (&ExprKind::Index(ref la, ref li), &ExprKind::Index(ref ra, ref ri)) => self.eq_expr(la, ra) && self.eq_expr(li, ri),
118 (&ExprKind::If(ref lc, ref lt, ref le), &ExprKind::If(ref rc, ref rt, ref re)) => {
119 self.eq_expr(lc, rc) && self.eq_expr(&**lt, &**rt) && both(le, re, |l, r| self.eq_expr(l, r))
121 (&ExprKind::Lit(ref l), &ExprKind::Lit(ref r)) => l.node == r.node,
122 (&ExprKind::Loop(ref lb, ref ll, ref lls), &ExprKind::Loop(ref rb, ref rl, ref rls)) => {
123 lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.as_str() == r.ident.as_str())
125 (&ExprKind::Match(ref le, ref la, ref ls), &ExprKind::Match(ref re, ref ra, ref rs)) => {
126 ls == rs && self.eq_expr(le, re) && over(la, ra, |l, r| {
127 self.eq_expr(&l.body, &r.body) && both(&l.guard, &r.guard, |l, r| self.eq_guard(l, r))
128 && over(&l.pats, &r.pats, |l, r| self.eq_pat(l, r))
131 (&ExprKind::MethodCall(ref l_path, _, ref l_args), &ExprKind::MethodCall(ref r_path, _, ref r_args)) => {
132 !self.ignore_fn && self.eq_path_segment(l_path, r_path) && self.eq_exprs(l_args, r_args)
134 (&ExprKind::Repeat(ref le, ref ll_id), &ExprKind::Repeat(ref re, ref rl_id)) => {
135 let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id.body));
136 let ll = celcx.expr(&self.cx.tcx.hir.body(ll_id.body).value);
137 let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(rl_id.body));
138 let rl = celcx.expr(&self.cx.tcx.hir.body(rl_id.body).value);
140 self.eq_expr(le, re) && ll == rl
142 (&ExprKind::Ret(ref l), &ExprKind::Ret(ref r)) => both(l, r, |l, r| self.eq_expr(l, r)),
143 (&ExprKind::Path(ref l), &ExprKind::Path(ref r)) => self.eq_qpath(l, r),
144 (&ExprKind::Struct(ref l_path, ref lf, ref lo), &ExprKind::Struct(ref r_path, ref rf, ref ro)) => {
145 self.eq_qpath(l_path, r_path) && both(lo, ro, |l, r| self.eq_expr(l, r))
146 && over(lf, rf, |l, r| self.eq_field(l, r))
148 (&ExprKind::Tup(ref l_tup), &ExprKind::Tup(ref r_tup)) => self.eq_exprs(l_tup, r_tup),
149 (&ExprKind::Unary(l_op, ref le), &ExprKind::Unary(r_op, ref re)) => l_op == r_op && self.eq_expr(le, re),
150 (&ExprKind::Array(ref l), &ExprKind::Array(ref r)) => self.eq_exprs(l, r),
151 (&ExprKind::While(ref lc, ref lb, ref ll), &ExprKind::While(ref rc, ref rb, ref rl)) => {
152 self.eq_expr(lc, rc) && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.as_str() == r.ident.as_str())
158 fn eq_exprs(&mut self, left: &P<[Expr]>, right: &P<[Expr]>) -> bool {
159 over(left, right, |l, r| self.eq_expr(l, r))
162 fn eq_field(&mut self, left: &Field, right: &Field) -> bool {
163 left.ident.name == right.ident.name && self.eq_expr(&left.expr, &right.expr)
166 fn eq_guard(&mut self, left: &Guard, right: &Guard) -> bool {
167 match (left, right) {
168 (Guard::If(l), Guard::If(r)) => self.eq_expr(l, r),
172 fn eq_generic_arg(&mut self, left: &GenericArg, right: &GenericArg) -> bool {
173 match (left, right) {
174 (GenericArg::Lifetime(l_lt), GenericArg::Lifetime(r_lt)) => self.eq_lifetime(l_lt, r_lt),
175 (GenericArg::Type(l_ty), GenericArg::Type(r_ty)) => self.eq_ty(l_ty, r_ty),
180 fn eq_lifetime(&mut self, left: &Lifetime, right: &Lifetime) -> bool {
181 left.name == right.name
184 /// Check whether two patterns are the same.
185 pub fn eq_pat(&mut self, left: &Pat, right: &Pat) -> bool {
186 match (&left.node, &right.node) {
187 (&PatKind::Box(ref l), &PatKind::Box(ref r)) => self.eq_pat(l, r),
188 (&PatKind::TupleStruct(ref lp, ref la, ls), &PatKind::TupleStruct(ref rp, ref ra, rs)) => {
189 self.eq_qpath(lp, rp) && over(la, ra, |l, r| self.eq_pat(l, r)) && ls == rs
191 (&PatKind::Binding(ref lb, _, ref li, ref lp), &PatKind::Binding(ref rb, _, ref ri, ref rp)) => {
192 lb == rb && li.name.as_str() == ri.name.as_str() && both(lp, rp, |l, r| self.eq_pat(l, r))
194 (&PatKind::Path(ref l), &PatKind::Path(ref r)) => self.eq_qpath(l, r),
195 (&PatKind::Lit(ref l), &PatKind::Lit(ref r)) => self.eq_expr(l, r),
196 (&PatKind::Tuple(ref l, ls), &PatKind::Tuple(ref r, rs)) => {
197 ls == rs && over(l, r, |l, r| self.eq_pat(l, r))
199 (&PatKind::Range(ref ls, ref le, ref li), &PatKind::Range(ref rs, ref re, ref ri)) => {
200 self.eq_expr(ls, rs) && self.eq_expr(le, re) && (*li == *ri)
202 (&PatKind::Ref(ref le, ref lm), &PatKind::Ref(ref re, ref rm)) => lm == rm && self.eq_pat(le, re),
203 (&PatKind::Slice(ref ls, ref li, ref le), &PatKind::Slice(ref rs, ref ri, ref re)) => {
204 over(ls, rs, |l, r| self.eq_pat(l, r)) && over(le, re, |l, r| self.eq_pat(l, r))
205 && both(li, ri, |l, r| self.eq_pat(l, r))
207 (&PatKind::Wild, &PatKind::Wild) => true,
212 #[allow(clippy::similar_names)]
213 fn eq_qpath(&mut self, left: &QPath, right: &QPath) -> bool {
214 match (left, right) {
215 (&QPath::Resolved(ref lty, ref lpath), &QPath::Resolved(ref rty, ref rpath)) => {
216 both(lty, rty, |l, r| self.eq_ty(l, r)) && self.eq_path(lpath, rpath)
218 (&QPath::TypeRelative(ref lty, ref lseg), &QPath::TypeRelative(ref rty, ref rseg)) => {
219 self.eq_ty(lty, rty) && self.eq_path_segment(lseg, rseg)
225 fn eq_path(&mut self, left: &Path, right: &Path) -> bool {
226 left.is_global() == right.is_global()
227 && over(&left.segments, &right.segments, |l, r| self.eq_path_segment(l, r))
230 fn eq_path_parameters(&mut self, left: &GenericArgs, right: &GenericArgs) -> bool {
231 if !(left.parenthesized || right.parenthesized) {
232 over(&left.args, &right.args, |l, r| self.eq_generic_arg(l, r)) // FIXME(flip1995): may not work
233 && over(&left.bindings, &right.bindings, |l, r| self.eq_type_binding(l, r))
234 } else if left.parenthesized && right.parenthesized {
235 over(left.inputs(), right.inputs(), |l, r| self.eq_ty(l, r))
237 &Some(&left.bindings[0].ty),
238 &Some(&right.bindings[0].ty),
239 |l, r| self.eq_ty(l, r),
246 pub fn eq_path_segments(&mut self, left: &[PathSegment], right: &[PathSegment]) -> bool {
247 left.len() == right.len() && left.iter().zip(right).all(|(l, r)| self.eq_path_segment(l, r))
250 pub fn eq_path_segment(&mut self, left: &PathSegment, right: &PathSegment) -> bool {
251 // The == of idents doesn't work with different contexts,
252 // we have to be explicit about hygiene
253 if left.ident.as_str() != right.ident.as_str() {
256 match (&left.args, &right.args) {
257 (&None, &None) => true,
258 (&Some(ref l), &Some(ref r)) => self.eq_path_parameters(l, r),
263 pub fn eq_ty(&mut self, left: &Ty, right: &Ty) -> bool {
264 self.eq_ty_kind(&left.node, &right.node)
267 #[allow(clippy::similar_names)]
268 pub fn eq_ty_kind(&mut self, left: &TyKind, right: &TyKind) -> bool {
269 match (left, right) {
270 (&TyKind::Slice(ref l_vec), &TyKind::Slice(ref r_vec)) => self.eq_ty(l_vec, r_vec),
271 (&TyKind::Array(ref lt, ref ll_id), &TyKind::Array(ref rt, ref rl_id)) => {
272 let full_table = self.tables;
274 let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id.body));
275 self.tables = self.cx.tcx.body_tables(ll_id.body);
276 let ll = celcx.expr(&self.cx.tcx.hir.body(ll_id.body).value);
278 let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(rl_id.body));
279 self.tables = self.cx.tcx.body_tables(rl_id.body);
280 let rl = celcx.expr(&self.cx.tcx.hir.body(rl_id.body).value);
282 let eq_ty = self.eq_ty(lt, rt);
283 self.tables = full_table;
286 (&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),
287 (&TyKind::Rptr(_, ref l_rmut), &TyKind::Rptr(_, ref r_rmut)) => {
288 l_rmut.mutbl == r_rmut.mutbl && self.eq_ty(&*l_rmut.ty, &*r_rmut.ty)
290 (&TyKind::Path(ref l), &TyKind::Path(ref r)) => self.eq_qpath(l, r),
291 (&TyKind::Tup(ref l), &TyKind::Tup(ref r)) => over(l, r, |l, r| self.eq_ty(l, r)),
292 (&TyKind::Infer, &TyKind::Infer) => true,
297 fn eq_type_binding(&mut self, left: &TypeBinding, right: &TypeBinding) -> bool {
298 left.ident.name == right.ident.name && self.eq_ty(&left.ty, &right.ty)
302 fn swap_binop<'a>(binop: BinOpKind, lhs: &'a Expr, rhs: &'a Expr) -> Option<(BinOpKind, &'a Expr, &'a Expr)> {
310 BinOpKind::BitOr => Some((binop, rhs, lhs)),
311 BinOpKind::Lt => Some((BinOpKind::Gt, rhs, lhs)),
312 BinOpKind::Le => Some((BinOpKind::Ge, rhs, lhs)),
313 BinOpKind::Ge => Some((BinOpKind::Le, rhs, lhs)),
314 BinOpKind::Gt => Some((BinOpKind::Lt, rhs, lhs)),
321 BinOpKind::Or => None,
325 /// Check if the two `Option`s are both `None` or some equal values as per
327 fn both<X, F>(l: &Option<X>, r: &Option<X>, mut eq_fn: F) -> bool
329 F: FnMut(&X, &X) -> bool,
332 .map_or_else(|| r.is_none(), |x| r.as_ref().map_or(false, |y| eq_fn(x, y)))
335 /// Check if two slices are equal as per `eq_fn`.
336 fn over<X, F>(left: &[X], right: &[X], mut eq_fn: F) -> bool
338 F: FnMut(&X, &X) -> bool,
340 left.len() == right.len() && left.iter().zip(right).all(|(x, y)| eq_fn(x, y))
344 /// Type used to hash an ast element. This is different from the `Hash` trait
345 /// on ast types as this
346 /// trait would consider IDs and spans.
348 /// All expressions kind are hashed, but some might have a weaker hash.
349 pub struct SpanlessHash<'a, 'tcx: 'a> {
350 /// Context used to evaluate constant expressions.
351 cx: &'a LateContext<'a, 'tcx>,
352 tables: &'a TypeckTables<'tcx>,
356 impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
357 pub fn new(cx: &'a LateContext<'a, 'tcx>, tables: &'a TypeckTables<'tcx>) -> Self {
361 s: DefaultHasher::new(),
365 pub fn finish(&self) -> u64 {
369 pub fn hash_block(&mut self, b: &Block) {
374 if let Some(ref e) = b.expr {
379 BlockCheckMode::DefaultBlock => 0,
380 BlockCheckMode::UnsafeBlock(_) => 1,
381 BlockCheckMode::PushUnsafeBlock(_) => 2,
382 BlockCheckMode::PopUnsafeBlock(_) => 3,
386 #[allow(clippy::many_single_char_names)]
387 pub fn hash_expr(&mut self, e: &Expr) {
388 if let Some(e) = constant_simple(self.cx, self.tables, e) {
389 return e.hash(&mut self.s);
393 ExprKind::AddrOf(m, ref e) => {
394 let c: fn(_, _) -> _ = ExprKind::AddrOf;
399 ExprKind::Continue(i) => {
400 let c: fn(_) -> _ = ExprKind::Continue;
402 if let Some(i) = i.label {
403 self.hash_name(i.ident.name);
406 ExprKind::Yield(ref e) => {
407 let c: fn(_) -> _ = ExprKind::Yield;
411 ExprKind::Assign(ref l, ref r) => {
412 let c: fn(_, _) -> _ = ExprKind::Assign;
417 ExprKind::AssignOp(ref o, ref l, ref r) => {
418 let c: fn(_, _, _) -> _ = ExprKind::AssignOp;
424 ExprKind::Block(ref b, _) => {
425 let c: fn(_, _) -> _ = ExprKind::Block;
429 ExprKind::Binary(op, ref l, ref r) => {
430 let c: fn(_, _, _) -> _ = ExprKind::Binary;
432 op.node.hash(&mut self.s);
436 ExprKind::Break(i, ref j) => {
437 let c: fn(_, _) -> _ = ExprKind::Break;
439 if let Some(i) = i.label {
440 self.hash_name(i.ident.name);
442 if let Some(ref j) = *j {
446 ExprKind::Box(ref e) => {
447 let c: fn(_) -> _ = ExprKind::Box;
451 ExprKind::Call(ref fun, ref args) => {
452 let c: fn(_, _) -> _ = ExprKind::Call;
455 self.hash_exprs(args);
457 ExprKind::Cast(ref e, ref _ty) => {
458 let c: fn(_, _) -> _ = ExprKind::Cast;
463 ExprKind::Closure(cap, _, eid, _, _) => {
464 let c: fn(_, _, _, _, _) -> _ = ExprKind::Closure;
467 CaptureClause::CaptureByValue => 0,
468 CaptureClause::CaptureByRef => 1,
470 self.hash_expr(&self.cx.tcx.hir.body(eid).value);
472 ExprKind::Field(ref e, ref f) => {
473 let c: fn(_, _) -> _ = ExprKind::Field;
476 self.hash_name(f.name);
478 ExprKind::Index(ref a, ref i) => {
479 let c: fn(_, _) -> _ = ExprKind::Index;
484 ExprKind::InlineAsm(..) => {
485 let c: fn(_, _, _) -> _ = ExprKind::InlineAsm;
488 ExprKind::If(ref cond, ref t, ref e) => {
489 let c: fn(_, _, _) -> _ = ExprKind::If;
491 self.hash_expr(cond);
492 self.hash_expr(&**t);
493 if let Some(ref e) = *e {
497 ExprKind::Lit(ref l) => {
498 let c: fn(_) -> _ = ExprKind::Lit;
502 ExprKind::Loop(ref b, ref i, _) => {
503 let c: fn(_, _, _) -> _ = ExprKind::Loop;
506 if let Some(i) = *i {
507 self.hash_name(i.ident.name);
510 ExprKind::Match(ref e, ref arms, ref s) => {
511 let c: fn(_, _, _) -> _ = ExprKind::Match;
517 if let Some(ref e) = arm.guard {
520 self.hash_expr(&arm.body);
525 ExprKind::MethodCall(ref path, ref _tys, ref args) => {
526 let c: fn(_, _, _) -> _ = ExprKind::MethodCall;
528 self.hash_name(path.ident.name);
529 self.hash_exprs(args);
531 ExprKind::Repeat(ref e, ref l_id) => {
532 let c: fn(_, _) -> _ = ExprKind::Repeat;
535 let full_table = self.tables;
536 self.tables = self.cx.tcx.body_tables(l_id.body);
537 self.hash_expr(&self.cx.tcx.hir.body(l_id.body).value);
538 self.tables = full_table;
540 ExprKind::Ret(ref e) => {
541 let c: fn(_) -> _ = ExprKind::Ret;
543 if let Some(ref e) = *e {
547 ExprKind::Path(ref qpath) => {
548 let c: fn(_) -> _ = ExprKind::Path;
550 self.hash_qpath(qpath);
552 ExprKind::Struct(ref path, ref fields, ref expr) => {
553 let c: fn(_, _, _) -> _ = ExprKind::Struct;
556 self.hash_qpath(path);
559 self.hash_name(f.ident.name);
560 self.hash_expr(&f.expr);
563 if let Some(ref e) = *expr {
567 ExprKind::Tup(ref tup) => {
568 let c: fn(_) -> _ = ExprKind::Tup;
570 self.hash_exprs(tup);
572 ExprKind::Type(ref e, ref _ty) => {
573 let c: fn(_, _) -> _ = ExprKind::Type;
578 ExprKind::Unary(lop, ref le) => {
579 let c: fn(_, _) -> _ = ExprKind::Unary;
582 lop.hash(&mut self.s);
585 ExprKind::Array(ref v) => {
586 let c: fn(_) -> _ = ExprKind::Array;
591 ExprKind::While(ref cond, ref b, l) => {
592 let c: fn(_, _, _) -> _ = ExprKind::While;
595 self.hash_expr(cond);
598 self.hash_name(l.ident.name);
604 pub fn hash_exprs(&mut self, e: &P<[Expr]>) {
610 pub fn hash_name(&mut self, n: Name) {
611 n.as_str().hash(&mut self.s);
614 pub fn hash_qpath(&mut self, p: &QPath) {
616 QPath::Resolved(_, ref path) => {
617 self.hash_path(path);
619 QPath::TypeRelative(_, ref path) => {
620 self.hash_name(path.ident.name);
623 // self.cx.tables.qpath_def(p, id).hash(&mut self.s);
626 pub fn hash_path(&mut self, p: &Path) {
627 p.is_global().hash(&mut self.s);
628 for p in &p.segments {
629 self.hash_name(p.ident.name);
633 pub fn hash_stmt(&mut self, b: &Stmt) {
635 StmtKind::Decl(ref decl, _) => {
636 let c: fn(_, _) -> _ = StmtKind::Decl;
639 if let DeclKind::Local(ref local) = decl.node {
640 if let Some(ref init) = local.init {
641 self.hash_expr(init);
645 StmtKind::Expr(ref expr, _) => {
646 let c: fn(_, _) -> _ = StmtKind::Expr;
648 self.hash_expr(expr);
650 StmtKind::Semi(ref expr, _) => {
651 let c: fn(_, _) -> _ = StmtKind::Semi;
653 self.hash_expr(expr);
658 pub fn hash_guard(&mut self, g: &Guard) {
660 Guard::If(ref expr) => {
661 let c: fn(_) -> _ = Guard::If;
663 self.hash_expr(expr);