]> git.lizzy.rs Git - rust.git/blob - clippy_lints/src/utils/hir.rs
Implement more `hir` typed node comparison
[rust.git] / clippy_lints / src / utils / hir.rs
1 use consts::constant;
2 use rustc::lint::*;
3 use rustc::hir::*;
4 use std::hash::{Hash, Hasher, SipHasher};
5 use syntax::ast::Name;
6 use syntax::ptr::P;
7 use utils::differing_macro_contexts;
8
9 /// Type used to check whether two ast are the same. This is different from the operator
10 /// `==` on ast types as this operator would compare true equality with ID and span.
11 ///
12 /// Note that some expressions kinds are not considered but could be added.
13 pub struct SpanlessEq<'a, 'tcx: 'a> {
14     /// Context used to evaluate constant expressions.
15     cx: &'a LateContext<'a, 'tcx>,
16     /// If is true, never consider as equal expressions containing function calls.
17     ignore_fn: bool,
18 }
19
20 impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
21     pub fn new(cx: &'a LateContext<'a, 'tcx>) -> Self {
22         SpanlessEq {
23             cx: cx,
24             ignore_fn: false,
25         }
26     }
27
28     pub fn ignore_fn(self) -> Self {
29         SpanlessEq {
30             cx: self.cx,
31             ignore_fn: true,
32         }
33     }
34
35     /// Check whether two statements are the same.
36     pub fn eq_stmt(&self, left: &Stmt, right: &Stmt) -> bool {
37         match (&left.node, &right.node) {
38             (&StmtDecl(ref l, _), &StmtDecl(ref r, _)) => {
39                 if let (&DeclLocal(ref l), &DeclLocal(ref r)) = (&l.node, &r.node) {
40                     both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r)) &&
41                     both(&l.init, &r.init, |l, r| self.eq_expr(l, r))
42                 } else {
43                     false
44                 }
45             }
46             (&StmtExpr(ref l, _), &StmtExpr(ref r, _)) |
47             (&StmtSemi(ref l, _), &StmtSemi(ref r, _)) => self.eq_expr(l, r),
48             _ => false,
49         }
50     }
51
52     /// Check whether two blocks are the same.
53     pub fn eq_block(&self, left: &Block, right: &Block) -> bool {
54         over(&left.stmts, &right.stmts, |l, r| self.eq_stmt(l, r)) &&
55         both(&left.expr, &right.expr, |l, r| self.eq_expr(l, r))
56     }
57
58     pub fn eq_expr(&self, left: &Expr, right: &Expr) -> bool {
59         if self.ignore_fn && differing_macro_contexts(left.span, right.span) {
60             return false;
61         }
62
63         if let (Some(l), Some(r)) = (constant(self.cx, left), constant(self.cx, right)) {
64             if l == r {
65                 return true;
66             }
67         }
68
69         match (&left.node, &right.node) {
70             (&ExprAddrOf(l_mut, ref le), &ExprAddrOf(r_mut, ref re)) => l_mut == r_mut && self.eq_expr(le, re),
71             (&ExprAgain(li), &ExprAgain(ri)) => both(&li, &ri, |l, r| l.node.as_str() == r.node.as_str()),
72             (&ExprAssign(ref ll, ref lr), &ExprAssign(ref rl, ref rr)) => self.eq_expr(ll, rl) && self.eq_expr(lr, rr),
73             (&ExprAssignOp(ref lo, ref ll, ref lr), &ExprAssignOp(ref ro, ref rl, ref rr)) => {
74                 lo.node == ro.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
75             }
76             (&ExprBlock(ref l), &ExprBlock(ref r)) => self.eq_block(l, r),
77             (&ExprBinary(l_op, ref ll, ref lr), &ExprBinary(r_op, ref rl, ref rr)) => {
78                 l_op.node == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr) ||
79                 swap_binop(l_op.node, ll, lr).map_or(false, |(l_op, ll, lr)| {
80                     l_op == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
81                 })
82             }
83             (&ExprBreak(li), &ExprBreak(ri)) => both(&li, &ri, |l, r| l.node.as_str() == r.node.as_str()),
84             (&ExprBox(ref l), &ExprBox(ref r)) => self.eq_expr(l, r),
85             (&ExprCall(ref l_fun, ref l_args), &ExprCall(ref r_fun, ref r_args)) => {
86                 !self.ignore_fn && self.eq_expr(l_fun, r_fun) && self.eq_exprs(l_args, r_args)
87             }
88             (&ExprCast(ref lx, ref lt), &ExprCast(ref rx, ref rt)) => self.eq_expr(lx, rx) && self.eq_ty(lt, rt),
89             (&ExprField(ref l_f_exp, ref l_f_ident), &ExprField(ref r_f_exp, ref r_f_ident)) => {
90                 l_f_ident.node == r_f_ident.node && self.eq_expr(l_f_exp, r_f_exp)
91             }
92             (&ExprIndex(ref la, ref li), &ExprIndex(ref ra, ref ri)) => self.eq_expr(la, ra) && self.eq_expr(li, ri),
93             (&ExprIf(ref lc, ref lt, ref le), &ExprIf(ref rc, ref rt, ref re)) => {
94                 self.eq_expr(lc, rc) && self.eq_block(lt, rt) && both(le, re, |l, r| self.eq_expr(l, r))
95             }
96             (&ExprLit(ref l), &ExprLit(ref r)) => l.node == r.node,
97             (&ExprLoop(ref lb, ref ll), &ExprLoop(ref rb, ref rl)) => {
98                 self.eq_block(lb, rb) && both(ll, rl, |l, r| l.node.as_str() == r.node.as_str())
99             }
100             (&ExprMatch(ref le, ref la, ref ls), &ExprMatch(ref re, ref ra, ref rs)) => {
101                 ls == rs && self.eq_expr(le, re) &&
102                 over(la, ra, |l, r| {
103                     self.eq_expr(&l.body, &r.body) && both(&l.guard, &r.guard, |l, r| self.eq_expr(l, r)) &&
104                     over(&l.pats, &r.pats, |l, r| self.eq_pat(l, r))
105                 })
106             }
107             (&ExprMethodCall(ref l_name, ref l_tys, ref l_args),
108              &ExprMethodCall(ref r_name, ref r_tys, ref r_args)) => {
109                 !self.ignore_fn && l_name.node == r_name.node &&
110                 over(l_tys, r_tys, |l, r| self.eq_ty(l, r)) &&
111                 self.eq_exprs(l_args, r_args)
112             }
113             (&ExprRepeat(ref le, ref ll), &ExprRepeat(ref re, ref rl)) => self.eq_expr(le, re) && self.eq_expr(ll, rl),
114             (&ExprRet(ref l), &ExprRet(ref r)) => both(l, r, |l, r| self.eq_expr(l, r)),
115             (&ExprPath(ref l_qself, ref l_subpath), &ExprPath(ref r_qself, ref r_subpath)) => {
116                 both(l_qself, r_qself, |l, r| self.eq_qself(l, r)) && self.eq_path(l_subpath, r_subpath)
117             }
118             (&ExprStruct(ref l_path, ref lf, ref lo), &ExprStruct(ref r_path, ref rf, ref ro)) => {
119                 self.eq_path(l_path, r_path) && both(lo, ro, |l, r| self.eq_expr(l, r)) &&
120                 over(lf, rf, |l, r| self.eq_field(l, r))
121             }
122             (&ExprTup(ref l_tup), &ExprTup(ref r_tup)) => self.eq_exprs(l_tup, r_tup),
123             (&ExprTupField(ref le, li), &ExprTupField(ref re, ri)) => li.node == ri.node && self.eq_expr(le, re),
124             (&ExprUnary(l_op, ref le), &ExprUnary(r_op, ref re)) => l_op == r_op && self.eq_expr(le, re),
125             (&ExprVec(ref l), &ExprVec(ref r)) => self.eq_exprs(l, r),
126             (&ExprWhile(ref lc, ref lb, ref ll), &ExprWhile(ref rc, ref rb, ref rl)) => {
127                 self.eq_expr(lc, rc) && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.node.as_str() == r.node.as_str())
128             }
129             _ => false,
130         }
131     }
132
133     fn eq_exprs(&self, left: &[P<Expr>], right: &[P<Expr>]) -> bool {
134         over(left, right, |l, r| self.eq_expr(l, r))
135     }
136
137     fn eq_field(&self, left: &Field, right: &Field) -> bool {
138         left.name.node == right.name.node && self.eq_expr(&left.expr, &right.expr)
139     }
140
141     fn eq_lifetime(&self, left: &Lifetime, right: &Lifetime) -> bool {
142         left.name == right.name
143     }
144
145     /// Check whether two patterns are the same.
146     pub fn eq_pat(&self, left: &Pat, right: &Pat) -> bool {
147         match (&left.node, &right.node) {
148             (&PatKind::Box(ref l), &PatKind::Box(ref r)) => self.eq_pat(l, r),
149             (&PatKind::TupleStruct(ref lp, ref la, ls), &PatKind::TupleStruct(ref rp, ref ra, rs)) => {
150                 self.eq_path(lp, rp) && over(la, ra, |l, r| self.eq_pat(l, r)) && ls == rs
151             }
152             (&PatKind::Binding(ref lb, ref li, ref lp), &PatKind::Binding(ref rb, ref ri, ref rp)) => {
153                 lb == rb && li.node.as_str() == ri.node.as_str() && both(lp, rp, |l, r| self.eq_pat(l, r))
154             }
155             (&PatKind::Path(ref ql, ref l), &PatKind::Path(ref qr, ref r)) => {
156                 both(ql, qr, |ql, qr| self.eq_qself(ql, qr)) && self.eq_path(l, r)
157             }
158             (&PatKind::Lit(ref l), &PatKind::Lit(ref r)) => self.eq_expr(l, r),
159             (&PatKind::Tuple(ref l, ls), &PatKind::Tuple(ref r, rs)) => {
160                 ls == rs && over(l, r, |l, r| self.eq_pat(l, r))
161             }
162             (&PatKind::Range(ref ls, ref le), &PatKind::Range(ref rs, ref re)) => {
163                 self.eq_expr(ls, rs) && self.eq_expr(le, re)
164             }
165             (&PatKind::Ref(ref le, ref lm), &PatKind::Ref(ref re, ref rm)) => lm == rm && self.eq_pat(le, re),
166             (&PatKind::Vec(ref ls, ref li, ref le), &PatKind::Vec(ref rs, ref ri, ref re)) => {
167                 over(ls, rs, |l, r| self.eq_pat(l, r)) && over(le, re, |l, r| self.eq_pat(l, r)) &&
168                 both(li, ri, |l, r| self.eq_pat(l, r))
169             }
170             (&PatKind::Wild, &PatKind::Wild) => true,
171             _ => false,
172         }
173     }
174
175     fn eq_path(&self, left: &Path, right: &Path) -> bool {
176         left.global == right.global &&
177         over(&left.segments, &right.segments, |l, r| self.eq_path_segment(l, r))
178     }
179
180     fn eq_path_parameters(&self, left: &PathParameters, right: &PathParameters) -> bool {
181         match (left, right) {
182             (&AngleBracketedParameters(ref left), &AngleBracketedParameters(ref right)) => {
183                 over(&left.lifetimes, &right.lifetimes, |l, r| self.eq_lifetime(l, r)) &&
184                 over(&left.types, &right.types, |l, r| self.eq_ty(l, r)) &&
185                 over(&left.bindings, &right.bindings, |l, r| self.eq_type_binding(l, r))
186             }
187             (&ParenthesizedParameters(ref left), &ParenthesizedParameters(ref right)) => {
188                 over(&left.inputs, &right.inputs, |l, r| self.eq_ty(l, r)) &&
189                 both(&left.output, &right.output, |l, r| self.eq_ty(l, r))
190             }
191             (&AngleBracketedParameters(_), &ParenthesizedParameters(_)) |
192             (&ParenthesizedParameters(_), &AngleBracketedParameters(_)) => {
193                 false
194             }
195         }
196     }
197
198     fn eq_path_segment(&self, left: &PathSegment, right: &PathSegment) -> bool {
199         // The == of idents doesn't work with different contexts,
200         // we have to be explicit about hygiene
201         left.name.as_str() == right.name.as_str() &&
202         self.eq_path_parameters(&left.parameters, &right.parameters)
203     }
204
205     fn eq_qself(&self, left: &QSelf, right: &QSelf) -> bool {
206         left.ty.node == right.ty.node && left.position == right.position
207     }
208
209     fn eq_ty(&self, left: &Ty, right: &Ty) -> bool {
210         match (&left.node, &right.node) {
211             (&TyVec(ref l_vec), &TyVec(ref r_vec)) => self.eq_ty(l_vec, r_vec),
212             (&TyFixedLengthVec(ref lt, ref ll), &TyFixedLengthVec(ref rt, ref rl)) => {
213                 self.eq_ty(lt, rt) && self.eq_expr(ll, rl)
214             }
215             (&TyPtr(ref l_mut), &TyPtr(ref r_mut)) => l_mut.mutbl == r_mut.mutbl && self.eq_ty(&*l_mut.ty, &*r_mut.ty),
216             (&TyRptr(_, ref l_rmut), &TyRptr(_, ref r_rmut)) => {
217                 l_rmut.mutbl == r_rmut.mutbl && self.eq_ty(&*l_rmut.ty, &*r_rmut.ty)
218             }
219             (&TyPath(ref lq, ref l_path), &TyPath(ref rq, ref r_path)) => {
220                 both(lq, rq, |l, r| self.eq_qself(l, r)) && self.eq_path(l_path, r_path)
221             }
222             (&TyTup(ref l), &TyTup(ref r)) => over(l, r, |l, r| self.eq_ty(l, r)),
223             (&TyInfer, &TyInfer) => true,
224             _ => false,
225         }
226     }
227
228     fn eq_type_binding(&self, left: &TypeBinding, right: &TypeBinding) -> bool {
229         left.name == right.name && self.eq_ty(&left.ty, &right.ty)
230     }
231 }
232
233 fn swap_binop<'a>(binop: BinOp_, lhs: &'a Expr, rhs: &'a Expr) -> Option<(BinOp_, &'a Expr, &'a Expr)> {
234     match binop {
235         BiAdd |
236         BiMul |
237         BiBitXor |
238         BiBitAnd |
239         BiEq |
240         BiNe |
241         BiBitOr => Some((binop, rhs, lhs)),
242         BiLt => Some((BiGt, rhs, lhs)),
243         BiLe => Some((BiGe, rhs, lhs)),
244         BiGe => Some((BiLe, rhs, lhs)),
245         BiGt => Some((BiLt, rhs, lhs)),
246         BiShl | BiShr | BiRem | BiSub | BiDiv | BiAnd | BiOr => None,
247     }
248 }
249
250 /// Check if the two `Option`s are both `None` or some equal values as per `eq_fn`.
251 fn both<X, F>(l: &Option<X>, r: &Option<X>, mut eq_fn: F) -> bool
252     where F: FnMut(&X, &X) -> bool
253 {
254     l.as_ref().map_or_else(|| r.is_none(), |x| r.as_ref().map_or(false, |y| eq_fn(x, y)))
255 }
256
257 /// Check if two slices are equal as per `eq_fn`.
258 fn over<X, F>(left: &[X], right: &[X], mut eq_fn: F) -> bool
259     where F: FnMut(&X, &X) -> bool
260 {
261     left.len() == right.len() && left.iter().zip(right).all(|(x, y)| eq_fn(x, y))
262 }
263
264
265 /// Type used to hash an ast element. This is different from the `Hash` trait on ast types as this
266 /// trait would consider IDs and spans.
267 ///
268 /// All expressions kind are hashed, but some might have a weaker hash.
269 pub struct SpanlessHash<'a, 'tcx: 'a> {
270     /// Context used to evaluate constant expressions.
271     cx: &'a LateContext<'a, 'tcx>,
272     s: SipHasher,
273 }
274
275 impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
276     pub fn new(cx: &'a LateContext<'a, 'tcx>) -> Self {
277         SpanlessHash {
278             cx: cx,
279             s: SipHasher::new(),
280         }
281     }
282
283     pub fn finish(&self) -> u64 {
284         self.s.finish()
285     }
286
287     pub fn hash_block(&mut self, b: &Block) {
288         for s in &b.stmts {
289             self.hash_stmt(s);
290         }
291
292         if let Some(ref e) = b.expr {
293             self.hash_expr(e);
294         }
295
296         b.rules.hash(&mut self.s);
297     }
298
299     pub fn hash_expr(&mut self, e: &Expr) {
300         if let Some(e) = constant(self.cx, e) {
301             return e.hash(&mut self.s);
302         }
303
304         match e.node {
305             ExprAddrOf(m, ref e) => {
306                 let c: fn(_, _) -> _ = ExprAddrOf;
307                 c.hash(&mut self.s);
308                 m.hash(&mut self.s);
309                 self.hash_expr(e);
310             }
311             ExprAgain(i) => {
312                 let c: fn(_) -> _ = ExprAgain;
313                 c.hash(&mut self.s);
314                 if let Some(i) = i {
315                     self.hash_name(&i.node);
316                 }
317             }
318             ExprAssign(ref l, ref r) => {
319                 let c: fn(_, _) -> _ = ExprAssign;
320                 c.hash(&mut self.s);
321                 self.hash_expr(l);
322                 self.hash_expr(r);
323             }
324             ExprAssignOp(ref o, ref l, ref r) => {
325                 let c: fn(_, _, _) -> _ = ExprAssignOp;
326                 c.hash(&mut self.s);
327                 o.hash(&mut self.s);
328                 self.hash_expr(l);
329                 self.hash_expr(r);
330             }
331             ExprBlock(ref b) => {
332                 let c: fn(_) -> _ = ExprBlock;
333                 c.hash(&mut self.s);
334                 self.hash_block(b);
335             }
336             ExprBinary(op, ref l, ref r) => {
337                 let c: fn(_, _, _) -> _ = ExprBinary;
338                 c.hash(&mut self.s);
339                 op.node.hash(&mut self.s);
340                 self.hash_expr(l);
341                 self.hash_expr(r);
342             }
343             ExprBreak(i) => {
344                 let c: fn(_) -> _ = ExprBreak;
345                 c.hash(&mut self.s);
346                 if let Some(i) = i {
347                     self.hash_name(&i.node);
348                 }
349             }
350             ExprBox(ref e) => {
351                 let c: fn(_) -> _ = ExprBox;
352                 c.hash(&mut self.s);
353                 self.hash_expr(e);
354             }
355             ExprCall(ref fun, ref args) => {
356                 let c: fn(_, _) -> _ = ExprCall;
357                 c.hash(&mut self.s);
358                 self.hash_expr(fun);
359                 self.hash_exprs(args);
360             }
361             ExprCast(ref e, ref _ty) => {
362                 let c: fn(_, _) -> _ = ExprCast;
363                 c.hash(&mut self.s);
364                 self.hash_expr(e);
365                 // TODO: _ty
366             }
367             ExprClosure(cap, _, ref b, _) => {
368                 let c: fn(_, _, _, _) -> _ = ExprClosure;
369                 c.hash(&mut self.s);
370                 cap.hash(&mut self.s);
371                 self.hash_block(b);
372             }
373             ExprField(ref e, ref f) => {
374                 let c: fn(_, _) -> _ = ExprField;
375                 c.hash(&mut self.s);
376                 self.hash_expr(e);
377                 self.hash_name(&f.node);
378             }
379             ExprIndex(ref a, ref i) => {
380                 let c: fn(_, _) -> _ = ExprIndex;
381                 c.hash(&mut self.s);
382                 self.hash_expr(a);
383                 self.hash_expr(i);
384             }
385             ExprInlineAsm(..) => {
386                 let c: fn(_, _, _) -> _ = ExprInlineAsm;
387                 c.hash(&mut self.s);
388             }
389             ExprIf(ref cond, ref t, ref e) => {
390                 let c: fn(_, _, _) -> _ = ExprIf;
391                 c.hash(&mut self.s);
392                 self.hash_expr(cond);
393                 self.hash_block(t);
394                 if let Some(ref e) = *e {
395                     self.hash_expr(e);
396                 }
397             }
398             ExprLit(ref l) => {
399                 let c: fn(_) -> _ = ExprLit;
400                 c.hash(&mut self.s);
401                 l.hash(&mut self.s);
402             }
403             ExprLoop(ref b, ref i) => {
404                 let c: fn(_, _) -> _ = ExprLoop;
405                 c.hash(&mut self.s);
406                 self.hash_block(b);
407                 if let Some(i) = *i {
408                     self.hash_name(&i.node);
409                 }
410             }
411             ExprMatch(ref e, ref arms, ref s) => {
412                 let c: fn(_, _, _) -> _ = ExprMatch;
413                 c.hash(&mut self.s);
414                 self.hash_expr(e);
415
416                 for arm in arms {
417                     // TODO: arm.pat?
418                     if let Some(ref e) = arm.guard {
419                         self.hash_expr(e);
420                     }
421                     self.hash_expr(&arm.body);
422                 }
423
424                 s.hash(&mut self.s);
425             }
426             ExprMethodCall(ref name, ref _tys, ref args) => {
427                 let c: fn(_, _, _) -> _ = ExprMethodCall;
428                 c.hash(&mut self.s);
429                 self.hash_name(&name.node);
430                 self.hash_exprs(args);
431             }
432             ExprRepeat(ref e, ref l) => {
433                 let c: fn(_, _) -> _ = ExprRepeat;
434                 c.hash(&mut self.s);
435                 self.hash_expr(e);
436                 self.hash_expr(l);
437             }
438             ExprRet(ref e) => {
439                 let c: fn(_) -> _ = ExprRet;
440                 c.hash(&mut self.s);
441                 if let Some(ref e) = *e {
442                     self.hash_expr(e);
443                 }
444             }
445             ExprPath(ref _qself, ref subpath) => {
446                 let c: fn(_, _) -> _ = ExprPath;
447                 c.hash(&mut self.s);
448                 self.hash_path(subpath);
449             }
450             ExprStruct(ref path, ref fields, ref expr) => {
451                 let c: fn(_, _, _) -> _ = ExprStruct;
452                 c.hash(&mut self.s);
453
454                 self.hash_path(path);
455
456                 for f in fields {
457                     self.hash_name(&f.name.node);
458                     self.hash_expr(&f.expr);
459                 }
460
461                 if let Some(ref e) = *expr {
462                     self.hash_expr(e);
463                 }
464             }
465             ExprTup(ref tup) => {
466                 let c: fn(_) -> _ = ExprTup;
467                 c.hash(&mut self.s);
468                 self.hash_exprs(tup);
469             }
470             ExprTupField(ref le, li) => {
471                 let c: fn(_, _) -> _ = ExprTupField;
472                 c.hash(&mut self.s);
473
474                 self.hash_expr(le);
475                 li.node.hash(&mut self.s);
476             }
477             ExprType(_, _) => {
478                 let c: fn(_, _) -> _ = ExprType;
479                 c.hash(&mut self.s);
480                 // what’s an ExprType anyway?
481             }
482             ExprUnary(lop, ref le) => {
483                 let c: fn(_, _) -> _ = ExprUnary;
484                 c.hash(&mut self.s);
485
486                 lop.hash(&mut self.s);
487                 self.hash_expr(le);
488             }
489             ExprVec(ref v) => {
490                 let c: fn(_) -> _ = ExprVec;
491                 c.hash(&mut self.s);
492
493                 self.hash_exprs(v);
494             }
495             ExprWhile(ref cond, ref b, l) => {
496                 let c: fn(_, _, _) -> _ = ExprWhile;
497                 c.hash(&mut self.s);
498
499                 self.hash_expr(cond);
500                 self.hash_block(b);
501                 if let Some(l) = l {
502                     self.hash_name(&l.node);
503                 }
504             }
505         }
506     }
507
508     pub fn hash_exprs(&mut self, e: &[P<Expr>]) {
509         for e in e {
510             self.hash_expr(e);
511         }
512     }
513
514     pub fn hash_name(&mut self, n: &Name) {
515         n.as_str().hash(&mut self.s);
516     }
517
518     pub fn hash_path(&mut self, p: &Path) {
519         p.global.hash(&mut self.s);
520         for p in &p.segments {
521             self.hash_name(&p.name);
522         }
523     }
524
525     pub fn hash_stmt(&mut self, b: &Stmt) {
526         match b.node {
527             StmtDecl(ref _decl, _) => {
528                 let c: fn(_, _) -> _ = StmtDecl;
529                 c.hash(&mut self.s);
530                 // TODO: decl
531             }
532             StmtExpr(ref expr, _) => {
533                 let c: fn(_, _) -> _ = StmtExpr;
534                 c.hash(&mut self.s);
535                 self.hash_expr(expr);
536             }
537             StmtSemi(ref expr, _) => {
538                 let c: fn(_, _) -> _ = StmtSemi;
539                 c.hash(&mut self.s);
540                 self.hash_expr(expr);
541             }
542         }
543     }
544 }