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::utils::differing_macro_contexts;
13 use rustc::lint::LateContext;
14 use rustc::ty::TypeckTables;
15 use std::collections::hash_map::DefaultHasher;
16 use std::hash::{Hash, Hasher};
17 use syntax::ast::Name;
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 self.eq_pat(&l.pat, &r.pat)
58 && both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r))
59 && both(&l.init, &r.init, |l, r| self.eq_expr(l, r))
64 (&StmtKind::Expr(ref l, _), &StmtKind::Expr(ref r, _))
65 | (&StmtKind::Semi(ref l, _), &StmtKind::Semi(ref r, _)) => self.eq_expr(l, 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)) = (
83 constant_simple(self.cx, self.tables, left),
84 constant_simple(self.cx, self.tables, right),
91 match (&left.node, &right.node) {
92 (&ExprKind::AddrOf(l_mut, ref le), &ExprKind::AddrOf(r_mut, ref re)) => {
93 l_mut == r_mut && self.eq_expr(le, re)
95 (&ExprKind::Continue(li), &ExprKind::Continue(ri)) => {
96 both(&li.label, &ri.label, |l, r| l.ident.as_str() == r.ident.as_str())
98 (&ExprKind::Assign(ref ll, ref lr), &ExprKind::Assign(ref rl, ref rr)) => {
99 self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
101 (&ExprKind::AssignOp(ref lo, ref ll, ref lr), &ExprKind::AssignOp(ref ro, ref rl, ref rr)) => {
102 lo.node == ro.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
104 (&ExprKind::Block(ref l, _), &ExprKind::Block(ref r, _)) => self.eq_block(l, r),
105 (&ExprKind::Binary(l_op, ref ll, ref lr), &ExprKind::Binary(r_op, ref rl, ref rr)) => {
106 l_op.node == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
107 || swap_binop(l_op.node, ll, lr).map_or(false, |(l_op, ll, lr)| {
108 l_op == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
111 (&ExprKind::Break(li, ref le), &ExprKind::Break(ri, ref re)) => {
112 both(&li.label, &ri.label, |l, r| l.ident.as_str() == r.ident.as_str())
113 && both(le, re, |l, r| self.eq_expr(l, r))
115 (&ExprKind::Box(ref l), &ExprKind::Box(ref r)) => self.eq_expr(l, r),
116 (&ExprKind::Call(ref l_fun, ref l_args), &ExprKind::Call(ref r_fun, ref r_args)) => {
117 !self.ignore_fn && self.eq_expr(l_fun, r_fun) && self.eq_exprs(l_args, r_args)
119 (&ExprKind::Cast(ref lx, ref lt), &ExprKind::Cast(ref rx, ref rt))
120 | (&ExprKind::Type(ref lx, ref lt), &ExprKind::Type(ref rx, ref rt)) => {
121 self.eq_expr(lx, rx) && self.eq_ty(lt, rt)
123 (&ExprKind::Field(ref l_f_exp, ref l_f_ident), &ExprKind::Field(ref r_f_exp, ref r_f_ident)) => {
124 l_f_ident.name == r_f_ident.name && self.eq_expr(l_f_exp, r_f_exp)
126 (&ExprKind::Index(ref la, ref li), &ExprKind::Index(ref ra, ref ri)) => {
127 self.eq_expr(la, ra) && self.eq_expr(li, ri)
129 (&ExprKind::If(ref lc, ref lt, ref le), &ExprKind::If(ref rc, ref rt, ref re)) => {
130 self.eq_expr(lc, rc) && self.eq_expr(&**lt, &**rt) && both(le, re, |l, r| self.eq_expr(l, r))
132 (&ExprKind::Lit(ref l), &ExprKind::Lit(ref r)) => l.node == r.node,
133 (&ExprKind::Loop(ref lb, ref ll, ref lls), &ExprKind::Loop(ref rb, ref rl, ref rls)) => {
134 lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.as_str() == r.ident.as_str())
136 (&ExprKind::Match(ref le, ref la, ref ls), &ExprKind::Match(ref re, ref ra, ref rs)) => {
138 && self.eq_expr(le, re)
139 && over(la, ra, |l, r| {
140 self.eq_expr(&l.body, &r.body)
141 && both(&l.guard, &r.guard, |l, r| self.eq_guard(l, r))
142 && over(&l.pats, &r.pats, |l, r| self.eq_pat(l, r))
145 (&ExprKind::MethodCall(ref l_path, _, ref l_args), &ExprKind::MethodCall(ref r_path, _, ref r_args)) => {
146 !self.ignore_fn && self.eq_path_segment(l_path, r_path) && self.eq_exprs(l_args, r_args)
148 (&ExprKind::Repeat(ref le, ref ll_id), &ExprKind::Repeat(ref re, ref rl_id)) => {
149 let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id.body));
150 let ll = celcx.expr(&self.cx.tcx.hir().body(ll_id.body).value);
151 let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(rl_id.body));
152 let rl = celcx.expr(&self.cx.tcx.hir().body(rl_id.body).value);
154 self.eq_expr(le, re) && ll == rl
156 (&ExprKind::Ret(ref l), &ExprKind::Ret(ref r)) => both(l, r, |l, r| self.eq_expr(l, r)),
157 (&ExprKind::Path(ref l), &ExprKind::Path(ref r)) => self.eq_qpath(l, r),
158 (&ExprKind::Struct(ref l_path, ref lf, ref lo), &ExprKind::Struct(ref r_path, ref rf, ref ro)) => {
159 self.eq_qpath(l_path, r_path)
160 && both(lo, ro, |l, r| self.eq_expr(l, r))
161 && over(lf, rf, |l, r| self.eq_field(l, r))
163 (&ExprKind::Tup(ref l_tup), &ExprKind::Tup(ref r_tup)) => self.eq_exprs(l_tup, r_tup),
164 (&ExprKind::Unary(l_op, ref le), &ExprKind::Unary(r_op, ref re)) => l_op == r_op && self.eq_expr(le, re),
165 (&ExprKind::Array(ref l), &ExprKind::Array(ref r)) => self.eq_exprs(l, r),
166 (&ExprKind::While(ref lc, ref lb, ref ll), &ExprKind::While(ref rc, ref rb, ref rl)) => {
168 && self.eq_block(lb, rb)
169 && both(ll, rl, |l, r| l.ident.as_str() == r.ident.as_str())
175 fn eq_exprs(&mut self, left: &P<[Expr]>, right: &P<[Expr]>) -> bool {
176 over(left, right, |l, r| self.eq_expr(l, r))
179 fn eq_field(&mut self, left: &Field, right: &Field) -> bool {
180 left.ident.name == right.ident.name && self.eq_expr(&left.expr, &right.expr)
183 fn eq_guard(&mut self, left: &Guard, right: &Guard) -> bool {
184 match (left, right) {
185 (Guard::If(l), Guard::If(r)) => self.eq_expr(l, r),
189 fn eq_generic_arg(&mut self, left: &GenericArg, right: &GenericArg) -> bool {
190 match (left, right) {
191 (GenericArg::Lifetime(l_lt), GenericArg::Lifetime(r_lt)) => self.eq_lifetime(l_lt, r_lt),
192 (GenericArg::Type(l_ty), GenericArg::Type(r_ty)) => self.eq_ty(l_ty, r_ty),
197 fn eq_lifetime(&mut self, left: &Lifetime, right: &Lifetime) -> bool {
198 left.name == right.name
201 /// Check whether two patterns are the same.
202 pub fn eq_pat(&mut self, left: &Pat, right: &Pat) -> bool {
203 match (&left.node, &right.node) {
204 (&PatKind::Box(ref l), &PatKind::Box(ref r)) => self.eq_pat(l, r),
205 (&PatKind::TupleStruct(ref lp, ref la, ls), &PatKind::TupleStruct(ref rp, ref ra, rs)) => {
206 self.eq_qpath(lp, rp) && over(la, ra, |l, r| self.eq_pat(l, r)) && ls == rs
208 (&PatKind::Binding(ref lb, _, ref li, ref lp), &PatKind::Binding(ref rb, _, ref ri, ref rp)) => {
209 lb == rb && li.name.as_str() == ri.name.as_str() && both(lp, rp, |l, r| self.eq_pat(l, r))
211 (&PatKind::Path(ref l), &PatKind::Path(ref r)) => self.eq_qpath(l, r),
212 (&PatKind::Lit(ref l), &PatKind::Lit(ref r)) => self.eq_expr(l, r),
213 (&PatKind::Tuple(ref l, ls), &PatKind::Tuple(ref r, rs)) => {
214 ls == rs && over(l, r, |l, r| self.eq_pat(l, r))
216 (&PatKind::Range(ref ls, ref le, ref li), &PatKind::Range(ref rs, ref re, ref ri)) => {
217 self.eq_expr(ls, rs) && self.eq_expr(le, re) && (*li == *ri)
219 (&PatKind::Ref(ref le, ref lm), &PatKind::Ref(ref re, ref rm)) => lm == rm && self.eq_pat(le, re),
220 (&PatKind::Slice(ref ls, ref li, ref le), &PatKind::Slice(ref rs, ref ri, ref re)) => {
221 over(ls, rs, |l, r| self.eq_pat(l, r))
222 && over(le, re, |l, r| self.eq_pat(l, r))
223 && both(li, ri, |l, r| self.eq_pat(l, r))
225 (&PatKind::Wild, &PatKind::Wild) => true,
230 #[allow(clippy::similar_names)]
231 fn eq_qpath(&mut self, left: &QPath, right: &QPath) -> bool {
232 match (left, right) {
233 (&QPath::Resolved(ref lty, ref lpath), &QPath::Resolved(ref rty, ref rpath)) => {
234 both(lty, rty, |l, r| self.eq_ty(l, r)) && self.eq_path(lpath, rpath)
236 (&QPath::TypeRelative(ref lty, ref lseg), &QPath::TypeRelative(ref rty, ref rseg)) => {
237 self.eq_ty(lty, rty) && self.eq_path_segment(lseg, rseg)
243 fn eq_path(&mut self, left: &Path, right: &Path) -> bool {
244 left.is_global() == right.is_global()
245 && over(&left.segments, &right.segments, |l, r| self.eq_path_segment(l, r))
248 fn eq_path_parameters(&mut self, left: &GenericArgs, right: &GenericArgs) -> bool {
249 if !(left.parenthesized || right.parenthesized) {
250 over(&left.args, &right.args, |l, r| self.eq_generic_arg(l, r)) // FIXME(flip1995): may not work
251 && over(&left.bindings, &right.bindings, |l, r| self.eq_type_binding(l, r))
252 } else if left.parenthesized && right.parenthesized {
253 over(left.inputs(), right.inputs(), |l, r| self.eq_ty(l, r))
254 && both(&Some(&left.bindings[0].ty), &Some(&right.bindings[0].ty), |l, r| {
262 pub fn eq_path_segments(&mut self, left: &[PathSegment], right: &[PathSegment]) -> bool {
263 left.len() == right.len() && left.iter().zip(right).all(|(l, r)| self.eq_path_segment(l, r))
266 pub fn eq_path_segment(&mut self, left: &PathSegment, right: &PathSegment) -> bool {
267 // The == of idents doesn't work with different contexts,
268 // we have to be explicit about hygiene
269 if left.ident.as_str() != right.ident.as_str() {
272 match (&left.args, &right.args) {
273 (&None, &None) => true,
274 (&Some(ref l), &Some(ref r)) => self.eq_path_parameters(l, r),
279 pub fn eq_ty(&mut self, left: &Ty, right: &Ty) -> bool {
280 self.eq_ty_kind(&left.node, &right.node)
283 #[allow(clippy::similar_names)]
284 pub fn eq_ty_kind(&mut self, left: &TyKind, right: &TyKind) -> bool {
285 match (left, right) {
286 (&TyKind::Slice(ref l_vec), &TyKind::Slice(ref r_vec)) => self.eq_ty(l_vec, r_vec),
287 (&TyKind::Array(ref lt, ref ll_id), &TyKind::Array(ref rt, ref rl_id)) => {
288 let full_table = self.tables;
290 let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id.body));
291 self.tables = self.cx.tcx.body_tables(ll_id.body);
292 let ll = celcx.expr(&self.cx.tcx.hir().body(ll_id.body).value);
294 let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(rl_id.body));
295 self.tables = self.cx.tcx.body_tables(rl_id.body);
296 let rl = celcx.expr(&self.cx.tcx.hir().body(rl_id.body).value);
298 let eq_ty = self.eq_ty(lt, rt);
299 self.tables = full_table;
302 (&TyKind::Ptr(ref l_mut), &TyKind::Ptr(ref r_mut)) => {
303 l_mut.mutbl == r_mut.mutbl && self.eq_ty(&*l_mut.ty, &*r_mut.ty)
305 (&TyKind::Rptr(_, ref l_rmut), &TyKind::Rptr(_, ref r_rmut)) => {
306 l_rmut.mutbl == r_rmut.mutbl && self.eq_ty(&*l_rmut.ty, &*r_rmut.ty)
308 (&TyKind::Path(ref l), &TyKind::Path(ref r)) => self.eq_qpath(l, r),
309 (&TyKind::Tup(ref l), &TyKind::Tup(ref r)) => over(l, r, |l, r| self.eq_ty(l, r)),
310 (&TyKind::Infer, &TyKind::Infer) => true,
315 fn eq_type_binding(&mut self, left: &TypeBinding, right: &TypeBinding) -> bool {
316 left.ident.name == right.ident.name && self.eq_ty(&left.ty, &right.ty)
320 fn swap_binop<'a>(binop: BinOpKind, lhs: &'a Expr, rhs: &'a Expr) -> Option<(BinOpKind, &'a Expr, &'a Expr)> {
328 | BinOpKind::BitOr => Some((binop, rhs, lhs)),
329 BinOpKind::Lt => Some((BinOpKind::Gt, rhs, lhs)),
330 BinOpKind::Le => Some((BinOpKind::Ge, rhs, lhs)),
331 BinOpKind::Ge => Some((BinOpKind::Le, rhs, lhs)),
332 BinOpKind::Gt => Some((BinOpKind::Lt, rhs, lhs)),
339 | BinOpKind::Or => None,
343 /// Check if the two `Option`s are both `None` or some equal values as per
345 fn both<X, F>(l: &Option<X>, r: &Option<X>, mut eq_fn: F) -> bool
347 F: FnMut(&X, &X) -> bool,
350 .map_or_else(|| r.is_none(), |x| r.as_ref().map_or(false, |y| eq_fn(x, y)))
353 /// Check if two slices are equal as per `eq_fn`.
354 fn over<X, F>(left: &[X], right: &[X], mut eq_fn: F) -> bool
356 F: FnMut(&X, &X) -> bool,
358 left.len() == right.len() && left.iter().zip(right).all(|(x, y)| eq_fn(x, y))
361 /// Type used to hash an ast element. This is different from the `Hash` trait
362 /// on ast types as this
363 /// trait would consider IDs and spans.
365 /// All expressions kind are hashed, but some might have a weaker hash.
366 pub struct SpanlessHash<'a, 'tcx: 'a> {
367 /// Context used to evaluate constant expressions.
368 cx: &'a LateContext<'a, 'tcx>,
369 tables: &'a TypeckTables<'tcx>,
373 impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
374 pub fn new(cx: &'a LateContext<'a, 'tcx>, tables: &'a TypeckTables<'tcx>) -> Self {
378 s: DefaultHasher::new(),
382 pub fn finish(&self) -> u64 {
386 pub fn hash_block(&mut self, b: &Block) {
391 if let Some(ref e) = b.expr {
396 BlockCheckMode::DefaultBlock => 0,
397 BlockCheckMode::UnsafeBlock(_) => 1,
398 BlockCheckMode::PushUnsafeBlock(_) => 2,
399 BlockCheckMode::PopUnsafeBlock(_) => 3,
404 #[allow(clippy::many_single_char_names)]
405 pub fn hash_expr(&mut self, e: &Expr) {
406 if let Some(e) = constant_simple(self.cx, self.tables, e) {
407 return e.hash(&mut self.s);
411 ExprKind::AddrOf(m, ref e) => {
412 let c: fn(_, _) -> _ = ExprKind::AddrOf;
417 ExprKind::Continue(i) => {
418 let c: fn(_) -> _ = ExprKind::Continue;
420 if let Some(i) = i.label {
421 self.hash_name(i.ident.name);
424 ExprKind::Yield(ref e) => {
425 let c: fn(_) -> _ = ExprKind::Yield;
429 ExprKind::Assign(ref l, ref r) => {
430 let c: fn(_, _) -> _ = ExprKind::Assign;
435 ExprKind::AssignOp(ref o, ref l, ref r) => {
436 let c: fn(_, _, _) -> _ = ExprKind::AssignOp;
442 ExprKind::Block(ref b, _) => {
443 let c: fn(_, _) -> _ = ExprKind::Block;
447 ExprKind::Binary(op, ref l, ref r) => {
448 let c: fn(_, _, _) -> _ = ExprKind::Binary;
450 op.node.hash(&mut self.s);
454 ExprKind::Break(i, ref j) => {
455 let c: fn(_, _) -> _ = ExprKind::Break;
457 if let Some(i) = i.label {
458 self.hash_name(i.ident.name);
460 if let Some(ref j) = *j {
464 ExprKind::Box(ref e) => {
465 let c: fn(_) -> _ = ExprKind::Box;
469 ExprKind::Call(ref fun, ref args) => {
470 let c: fn(_, _) -> _ = ExprKind::Call;
473 self.hash_exprs(args);
475 ExprKind::Cast(ref e, ref _ty) => {
476 let c: fn(_, _) -> _ = ExprKind::Cast;
481 ExprKind::Closure(cap, _, eid, _, _) => {
482 let c: fn(_, _, _, _, _) -> _ = ExprKind::Closure;
485 CaptureClause::CaptureByValue => 0,
486 CaptureClause::CaptureByRef => 1,
489 self.hash_expr(&self.cx.tcx.hir().body(eid).value);
491 ExprKind::Field(ref e, ref f) => {
492 let c: fn(_, _) -> _ = ExprKind::Field;
495 self.hash_name(f.name);
497 ExprKind::Index(ref a, ref i) => {
498 let c: fn(_, _) -> _ = ExprKind::Index;
503 ExprKind::InlineAsm(..) => {
504 let c: fn(_, _, _) -> _ = ExprKind::InlineAsm;
507 ExprKind::If(ref cond, ref t, ref e) => {
508 let c: fn(_, _, _) -> _ = ExprKind::If;
510 self.hash_expr(cond);
511 self.hash_expr(&**t);
512 if let Some(ref e) = *e {
516 ExprKind::Lit(ref l) => {
517 let c: fn(_) -> _ = ExprKind::Lit;
521 ExprKind::Loop(ref b, ref i, _) => {
522 let c: fn(_, _, _) -> _ = ExprKind::Loop;
525 if let Some(i) = *i {
526 self.hash_name(i.ident.name);
529 ExprKind::Match(ref e, ref arms, ref s) => {
530 let c: fn(_, _, _) -> _ = ExprKind::Match;
536 if let Some(ref e) = arm.guard {
539 self.hash_expr(&arm.body);
544 ExprKind::MethodCall(ref path, ref _tys, ref args) => {
545 let c: fn(_, _, _) -> _ = ExprKind::MethodCall;
547 self.hash_name(path.ident.name);
548 self.hash_exprs(args);
550 ExprKind::Repeat(ref e, ref l_id) => {
551 let c: fn(_, _) -> _ = ExprKind::Repeat;
554 let full_table = self.tables;
555 self.tables = self.cx.tcx.body_tables(l_id.body);
556 self.hash_expr(&self.cx.tcx.hir().body(l_id.body).value);
557 self.tables = full_table;
559 ExprKind::Ret(ref e) => {
560 let c: fn(_) -> _ = ExprKind::Ret;
562 if let Some(ref e) = *e {
566 ExprKind::Path(ref qpath) => {
567 let c: fn(_) -> _ = ExprKind::Path;
569 self.hash_qpath(qpath);
571 ExprKind::Struct(ref path, ref fields, ref expr) => {
572 let c: fn(_, _, _) -> _ = ExprKind::Struct;
575 self.hash_qpath(path);
578 self.hash_name(f.ident.name);
579 self.hash_expr(&f.expr);
582 if let Some(ref e) = *expr {
586 ExprKind::Tup(ref tup) => {
587 let c: fn(_) -> _ = ExprKind::Tup;
589 self.hash_exprs(tup);
591 ExprKind::Type(ref e, ref _ty) => {
592 let c: fn(_, _) -> _ = ExprKind::Type;
597 ExprKind::Unary(lop, ref le) => {
598 let c: fn(_, _) -> _ = ExprKind::Unary;
601 lop.hash(&mut self.s);
604 ExprKind::Array(ref v) => {
605 let c: fn(_) -> _ = ExprKind::Array;
610 ExprKind::While(ref cond, ref b, l) => {
611 let c: fn(_, _, _) -> _ = ExprKind::While;
614 self.hash_expr(cond);
617 self.hash_name(l.ident.name);
624 pub fn hash_exprs(&mut self, e: &P<[Expr]>) {
630 pub fn hash_name(&mut self, n: Name) {
631 n.as_str().hash(&mut self.s);
634 pub fn hash_qpath(&mut self, p: &QPath) {
636 QPath::Resolved(_, ref path) => {
637 self.hash_path(path);
639 QPath::TypeRelative(_, ref path) => {
640 self.hash_name(path.ident.name);
643 // self.cx.tables.qpath_def(p, id).hash(&mut self.s);
646 pub fn hash_path(&mut self, p: &Path) {
647 p.is_global().hash(&mut self.s);
648 for p in &p.segments {
649 self.hash_name(p.ident.name);
653 pub fn hash_stmt(&mut self, b: &Stmt) {
655 StmtKind::Decl(ref decl, _) => {
656 let c: fn(_, _) -> _ = StmtKind::Decl;
659 if let DeclKind::Local(ref local) = decl.node {
660 if let Some(ref init) = local.init {
661 self.hash_expr(init);
665 StmtKind::Expr(ref expr, _) => {
666 let c: fn(_, _) -> _ = StmtKind::Expr;
668 self.hash_expr(expr);
670 StmtKind::Semi(ref expr, _) => {
671 let c: fn(_, _) -> _ = StmtKind::Semi;
673 self.hash_expr(expr);
678 pub fn hash_guard(&mut self, g: &Guard) {
680 Guard::If(ref expr) => {
681 let c: fn(_) -> _ = Guard::If;
683 self.hash_expr(expr);