]> git.lizzy.rs Git - rust.git/blob - src/librustc/ich/impls_hir.rs
Fix conversion from Miri Value to ConstValue
[rust.git] / src / librustc / ich / impls_hir.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! This module contains `HashStable` implementations for various HIR data
12 //! types in no particular order.
13
14 use hir;
15 use hir::map::DefPathHash;
16 use hir::def_id::{DefId, LocalDefId, CrateNum, CRATE_DEF_INDEX};
17 use ich::{StableHashingContext, NodeIdHashingMode};
18 use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey,
19                                            StableHasher, StableHasherResult};
20 use std::mem;
21 use syntax::ast;
22 use syntax::attr;
23
24 impl<'a> HashStable<StableHashingContext<'a>> for DefId {
25     #[inline]
26     fn hash_stable<W: StableHasherResult>(&self,
27                                           hcx: &mut StableHashingContext<'a>,
28                                           hasher: &mut StableHasher<W>) {
29         hcx.def_path_hash(*self).hash_stable(hcx, hasher);
30     }
31 }
32
33 impl<'a> ToStableHashKey<StableHashingContext<'a>> for DefId {
34     type KeyType = DefPathHash;
35
36     #[inline]
37     fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> DefPathHash {
38         hcx.def_path_hash(*self)
39     }
40 }
41
42 impl<'a> HashStable<StableHashingContext<'a>> for LocalDefId {
43     #[inline]
44     fn hash_stable<W: StableHasherResult>(&self,
45                                           hcx: &mut StableHashingContext<'a>,
46                                           hasher: &mut StableHasher<W>) {
47         hcx.def_path_hash(self.to_def_id()).hash_stable(hcx, hasher);
48     }
49 }
50
51 impl<'a> ToStableHashKey<StableHashingContext<'a>> for LocalDefId {
52     type KeyType = DefPathHash;
53
54     #[inline]
55     fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> DefPathHash {
56         hcx.def_path_hash(self.to_def_id())
57     }
58 }
59
60 impl<'a> HashStable<StableHashingContext<'a>> for CrateNum {
61     #[inline]
62     fn hash_stable<W: StableHasherResult>(&self,
63                                           hcx: &mut StableHashingContext<'a>,
64                                           hasher: &mut StableHasher<W>) {
65         hcx.def_path_hash(DefId {
66             krate: *self,
67             index: CRATE_DEF_INDEX
68         }).hash_stable(hcx, hasher);
69     }
70 }
71
72 impl<'a> ToStableHashKey<StableHashingContext<'a>> for CrateNum {
73     type KeyType = DefPathHash;
74
75     #[inline]
76     fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> DefPathHash {
77         let def_id = DefId { krate: *self, index: CRATE_DEF_INDEX };
78         def_id.to_stable_hash_key(hcx)
79     }
80 }
81
82 impl_stable_hash_for!(tuple_struct hir::ItemLocalId { index });
83
84 impl<'a> ToStableHashKey<StableHashingContext<'a>>
85 for hir::ItemLocalId {
86     type KeyType = hir::ItemLocalId;
87
88     #[inline]
89     fn to_stable_hash_key(&self,
90                           _: &StableHashingContext<'a>)
91                           -> hir::ItemLocalId {
92         *self
93     }
94 }
95
96 // The following implementations of HashStable for ItemId, TraitItemId, and
97 // ImplItemId deserve special attention. Normally we do not hash NodeIds within
98 // the HIR, since they just signify a HIR nodes own path. But ItemId et al
99 // are used when another item in the HIR is *referenced* and we certainly
100 // want to pick up on a reference changing its target, so we hash the NodeIds
101 // in "DefPath Mode".
102
103 impl<'a> HashStable<StableHashingContext<'a>> for hir::ItemId {
104     fn hash_stable<W: StableHasherResult>(&self,
105                                           hcx: &mut StableHashingContext<'a>,
106                                           hasher: &mut StableHasher<W>) {
107         let hir::ItemId {
108             id
109         } = *self;
110
111         hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
112             id.hash_stable(hcx, hasher);
113         })
114     }
115 }
116
117 impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItemId {
118     fn hash_stable<W: StableHasherResult>(&self,
119                                           hcx: &mut StableHashingContext<'a>,
120                                           hasher: &mut StableHasher<W>) {
121         let hir::TraitItemId {
122             node_id
123         } = * self;
124
125         hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
126             node_id.hash_stable(hcx, hasher);
127         })
128     }
129 }
130
131 impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItemId {
132     fn hash_stable<W: StableHasherResult>(&self,
133                                           hcx: &mut StableHashingContext<'a>,
134                                           hasher: &mut StableHasher<W>) {
135         let hir::ImplItemId {
136             node_id
137         } = * self;
138
139         hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
140             node_id.hash_stable(hcx, hasher);
141         })
142     }
143 }
144
145 impl_stable_hash_for!(enum hir::LifetimeName {
146     Implicit,
147     Underscore,
148     Fresh(index),
149     Static,
150     Name(name)
151 });
152
153 impl_stable_hash_for!(struct hir::Label {
154     span,
155     name
156 });
157
158 impl_stable_hash_for!(struct hir::Lifetime {
159     id,
160     span,
161     name
162 });
163
164 impl_stable_hash_for!(struct hir::LifetimeDef {
165     lifetime,
166     bounds,
167     pure_wrt_drop,
168     in_band
169 });
170
171 impl_stable_hash_for!(struct hir::Path {
172     span,
173     def,
174     segments
175 });
176
177 impl_stable_hash_for!(struct hir::PathSegment {
178     name,
179     infer_types,
180     parameters
181 });
182
183 impl_stable_hash_for!(struct hir::PathParameters {
184     lifetimes,
185     types,
186     bindings,
187     parenthesized
188 });
189
190 impl_stable_hash_for!(enum hir::TyParamBound {
191     TraitTyParamBound(poly_trait_ref, trait_bound_modifier),
192     RegionTyParamBound(lifetime)
193 });
194
195 impl_stable_hash_for!(enum hir::TraitBoundModifier {
196     None,
197     Maybe
198 });
199
200 impl_stable_hash_for!(struct hir::TyParam {
201     name,
202     id,
203     bounds,
204     default,
205     span,
206     pure_wrt_drop,
207     synthetic,
208     attrs
209 });
210
211 impl_stable_hash_for!(enum hir::GenericParam {
212     Lifetime(lifetime_def),
213     Type(ty_param)
214 });
215
216 impl_stable_hash_for!(struct hir::Generics {
217     params,
218     where_clause,
219     span
220 });
221
222 impl_stable_hash_for!(enum hir::SyntheticTyParamKind {
223     ImplTrait
224 });
225
226 impl_stable_hash_for!(struct hir::WhereClause {
227     id,
228     predicates
229 });
230
231 impl_stable_hash_for!(enum hir::WherePredicate {
232     BoundPredicate(pred),
233     RegionPredicate(pred),
234     EqPredicate(pred)
235 });
236
237 impl_stable_hash_for!(struct hir::WhereBoundPredicate {
238     span,
239     bound_generic_params,
240     bounded_ty,
241     bounds
242 });
243
244 impl_stable_hash_for!(struct hir::WhereRegionPredicate {
245     span,
246     lifetime,
247     bounds
248 });
249
250 impl_stable_hash_for!(struct hir::WhereEqPredicate {
251     id,
252     span,
253     lhs_ty,
254     rhs_ty
255 });
256
257 impl_stable_hash_for!(struct hir::MutTy {
258     ty,
259     mutbl
260 });
261
262 impl_stable_hash_for!(struct hir::MethodSig {
263     unsafety,
264     constness,
265     abi,
266     decl
267 });
268
269 impl_stable_hash_for!(struct hir::TypeBinding {
270     id,
271     name,
272     ty,
273     span
274 });
275
276 impl<'a> HashStable<StableHashingContext<'a>> for hir::Ty {
277     fn hash_stable<W: StableHasherResult>(&self,
278                                           hcx: &mut StableHashingContext<'a>,
279                                           hasher: &mut StableHasher<W>) {
280         hcx.while_hashing_hir_bodies(true, |hcx| {
281             let hir::Ty {
282                 id: _,
283                 hir_id: _,
284                 ref node,
285                 ref span,
286             } = *self;
287
288             node.hash_stable(hcx, hasher);
289             span.hash_stable(hcx, hasher);
290         })
291     }
292 }
293
294 impl_stable_hash_for!(enum hir::PrimTy {
295     TyInt(int_ty),
296     TyUint(uint_ty),
297     TyFloat(float_ty),
298     TyStr,
299     TyBool,
300     TyChar
301 });
302
303 impl_stable_hash_for!(struct hir::BareFnTy {
304     unsafety,
305     abi,
306     generic_params,
307     decl,
308     arg_names
309 });
310
311 impl_stable_hash_for!(struct hir::ExistTy {
312     generics,
313     bounds
314 });
315
316 impl_stable_hash_for!(enum hir::Ty_ {
317     TySlice(t),
318     TyArray(t, body_id),
319     TyPtr(t),
320     TyRptr(lifetime, t),
321     TyBareFn(t),
322     TyNever,
323     TyTup(ts),
324     TyPath(qpath),
325     TyTraitObject(trait_refs, lifetime),
326     TyImplTraitExistential(existty, lifetimes),
327     TyTypeof(body_id),
328     TyErr,
329     TyInfer
330 });
331
332 impl_stable_hash_for!(struct hir::FnDecl {
333     inputs,
334     output,
335     variadic,
336     has_implicit_self
337 });
338
339 impl_stable_hash_for!(enum hir::FunctionRetTy {
340     DefaultReturn(span),
341     Return(t)
342 });
343
344 impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitRef {
345     fn hash_stable<W: StableHasherResult>(&self,
346                                           hcx: &mut StableHashingContext<'a>,
347                                           hasher: &mut StableHasher<W>) {
348         let hir::TraitRef {
349             ref path,
350             // Don't hash the ref_id. It is tracked via the thing it is used to access
351             ref_id: _,
352         } = *self;
353
354         path.hash_stable(hcx, hasher);
355     }
356 }
357
358
359 impl_stable_hash_for!(struct hir::PolyTraitRef {
360     bound_generic_params,
361     trait_ref,
362     span
363 });
364
365 impl_stable_hash_for!(enum hir::QPath {
366     Resolved(t, path),
367     TypeRelative(t, path_segment)
368 });
369
370 impl_stable_hash_for!(struct hir::MacroDef {
371     name,
372     vis,
373     attrs,
374     id,
375     span,
376     legacy,
377     body
378 });
379
380
381 impl<'a> HashStable<StableHashingContext<'a>> for hir::Block {
382     fn hash_stable<W: StableHasherResult>(&self,
383                                           hcx: &mut StableHashingContext<'a>,
384                                           hasher: &mut StableHasher<W>) {
385         let hir::Block {
386             ref stmts,
387             ref expr,
388             id: _,
389             hir_id: _,
390             rules,
391             span,
392             targeted_by_break,
393             recovered,
394         } = *self;
395
396         stmts.hash_stable(hcx, hasher);
397         expr.hash_stable(hcx, hasher);
398         rules.hash_stable(hcx, hasher);
399         span.hash_stable(hcx, hasher);
400         recovered.hash_stable(hcx, hasher);
401         targeted_by_break.hash_stable(hcx, hasher);
402     }
403 }
404
405 impl<'a> HashStable<StableHashingContext<'a>> for hir::Pat {
406     fn hash_stable<W: StableHasherResult>(&self,
407                                           hcx: &mut StableHashingContext<'a>,
408                                           hasher: &mut StableHasher<W>) {
409         let hir::Pat {
410             id: _,
411             hir_id: _,
412             ref node,
413             ref span
414         } = *self;
415
416
417         node.hash_stable(hcx, hasher);
418         span.hash_stable(hcx, hasher);
419     }
420 }
421
422 impl_stable_hash_for_spanned!(hir::FieldPat);
423
424 impl<'a> HashStable<StableHashingContext<'a>> for hir::FieldPat {
425     fn hash_stable<W: StableHasherResult>(&self,
426                                           hcx: &mut StableHashingContext<'a>,
427                                           hasher: &mut StableHasher<W>) {
428         let hir::FieldPat {
429             id: _,
430             name,
431             ref pat,
432             is_shorthand,
433         } = *self;
434
435         name.hash_stable(hcx, hasher);
436         pat.hash_stable(hcx, hasher);
437         is_shorthand.hash_stable(hcx, hasher);
438     }
439 }
440
441 impl_stable_hash_for!(enum hir::BindingAnnotation {
442     Unannotated,
443     Mutable,
444     Ref,
445     RefMut
446 });
447
448 impl_stable_hash_for!(enum hir::RangeEnd {
449     Included,
450     Excluded
451 });
452
453 impl_stable_hash_for!(enum hir::PatKind {
454     Wild,
455     Binding(binding_mode, var, name, sub),
456     Struct(path, field_pats, dotdot),
457     TupleStruct(path, field_pats, dotdot),
458     Path(path),
459     Tuple(field_pats, dotdot),
460     Box(sub),
461     Ref(sub, mutability),
462     Lit(expr),
463     Range(start, end, end_kind),
464     Slice(one, two, three)
465 });
466
467 impl_stable_hash_for!(enum hir::BinOp_ {
468     BiAdd,
469     BiSub,
470     BiMul,
471     BiDiv,
472     BiRem,
473     BiAnd,
474     BiOr,
475     BiBitXor,
476     BiBitAnd,
477     BiBitOr,
478     BiShl,
479     BiShr,
480     BiEq,
481     BiLt,
482     BiLe,
483     BiNe,
484     BiGe,
485     BiGt
486 });
487
488 impl_stable_hash_for_spanned!(hir::BinOp_);
489
490 impl_stable_hash_for!(enum hir::UnOp {
491     UnDeref,
492     UnNot,
493     UnNeg
494 });
495
496 impl_stable_hash_for_spanned!(hir::Stmt_);
497
498 impl_stable_hash_for!(struct hir::Local {
499     pat,
500     ty,
501     init,
502     id,
503     hir_id,
504     span,
505     attrs,
506     source
507 });
508
509 impl_stable_hash_for_spanned!(hir::Decl_);
510 impl_stable_hash_for!(enum hir::Decl_ {
511     DeclLocal(local),
512     DeclItem(item_id)
513 });
514
515 impl_stable_hash_for!(struct hir::Arm {
516     attrs,
517     pats,
518     guard,
519     body
520 });
521
522 impl<'a> HashStable<StableHashingContext<'a>> for hir::Field {
523     fn hash_stable<W: StableHasherResult>(&self,
524                                           hcx: &mut StableHashingContext<'a>,
525                                           hasher: &mut StableHasher<W>) {
526         let hir::Field {
527             id: _,
528             name,
529             ref expr,
530             span,
531             is_shorthand,
532         } = *self;
533
534         name.hash_stable(hcx, hasher);
535         expr.hash_stable(hcx, hasher);
536         span.hash_stable(hcx, hasher);
537         is_shorthand.hash_stable(hcx, hasher);
538     }
539 }
540
541 impl_stable_hash_for_spanned!(ast::Name);
542
543
544 impl_stable_hash_for!(enum hir::BlockCheckMode {
545     DefaultBlock,
546     UnsafeBlock(src),
547     PushUnsafeBlock(src),
548     PopUnsafeBlock(src)
549 });
550
551 impl_stable_hash_for!(enum hir::UnsafeSource {
552     CompilerGenerated,
553     UserProvided
554 });
555
556 impl<'a> HashStable<StableHashingContext<'a>> for hir::Expr {
557     fn hash_stable<W: StableHasherResult>(&self,
558                                           hcx: &mut StableHashingContext<'a>,
559                                           hasher: &mut StableHasher<W>) {
560         hcx.while_hashing_hir_bodies(true, |hcx| {
561             let hir::Expr {
562                 id: _,
563                 hir_id: _,
564                 ref span,
565                 ref node,
566                 ref attrs
567             } = *self;
568
569             span.hash_stable(hcx, hasher);
570             node.hash_stable(hcx, hasher);
571             attrs.hash_stable(hcx, hasher);
572         })
573     }
574 }
575
576 impl_stable_hash_for!(enum hir::Expr_ {
577     ExprBox(sub),
578     ExprArray(subs),
579     ExprCall(callee, args),
580     ExprMethodCall(segment, span, args),
581     ExprTup(fields),
582     ExprBinary(op, lhs, rhs),
583     ExprUnary(op, operand),
584     ExprLit(value),
585     ExprCast(expr, t),
586     ExprType(expr, t),
587     ExprIf(cond, then, els),
588     ExprWhile(cond, body, label),
589     ExprLoop(body, label, loop_src),
590     ExprMatch(matchee, arms, match_src),
591     ExprClosure(capture_clause, decl, body_id, span, gen),
592     ExprBlock(blk),
593     ExprAssign(lhs, rhs),
594     ExprAssignOp(op, lhs, rhs),
595     ExprField(owner, field_name),
596     ExprIndex(lhs, rhs),
597     ExprPath(path),
598     ExprAddrOf(mutability, sub),
599     ExprBreak(destination, sub),
600     ExprAgain(destination),
601     ExprRet(val),
602     ExprInlineAsm(asm, inputs, outputs),
603     ExprStruct(path, fields, base),
604     ExprRepeat(val, times),
605     ExprYield(val)
606 });
607
608 impl_stable_hash_for!(enum hir::LocalSource {
609     Normal,
610     ForLoopDesugar
611 });
612
613 impl_stable_hash_for!(enum hir::LoopSource {
614     Loop,
615     WhileLet,
616     ForLoop
617 });
618
619 impl<'a> HashStable<StableHashingContext<'a>> for hir::MatchSource {
620     fn hash_stable<W: StableHasherResult>(&self,
621                                           hcx: &mut StableHashingContext<'a>,
622                                           hasher: &mut StableHasher<W>) {
623         use hir::MatchSource;
624
625         mem::discriminant(self).hash_stable(hcx, hasher);
626         match *self {
627             MatchSource::Normal |
628             MatchSource::WhileLetDesugar |
629             MatchSource::ForLoopDesugar |
630             MatchSource::TryDesugar => {
631                 // No fields to hash.
632             }
633             MatchSource::IfLetDesugar { contains_else_clause } => {
634                 contains_else_clause.hash_stable(hcx, hasher);
635             }
636         }
637     }
638 }
639
640 impl_stable_hash_for!(enum hir::GeneratorMovability {
641     Static,
642     Movable
643 });
644
645 impl_stable_hash_for!(enum hir::CaptureClause {
646     CaptureByValue,
647     CaptureByRef
648 });
649
650 impl_stable_hash_for_spanned!(usize);
651
652 impl_stable_hash_for!(struct hir::Destination {
653     label,
654     target_id
655 });
656
657 impl_stable_hash_for_spanned!(ast::Ident);
658
659 impl_stable_hash_for!(enum hir::LoopIdResult {
660     Ok(node_id),
661     Err(loop_id_error)
662 });
663
664 impl_stable_hash_for!(enum hir::LoopIdError {
665     OutsideLoopScope,
666     UnlabeledCfInWhileCondition,
667     UnresolvedLabel
668 });
669
670 impl_stable_hash_for!(enum hir::ScopeTarget {
671     Block(node_id),
672     Loop(loop_id_result)
673 });
674
675 impl<'a> HashStable<StableHashingContext<'a>> for ast::Ident {
676     fn hash_stable<W: StableHasherResult>(&self,
677                                           hcx: &mut StableHashingContext<'a>,
678                                           hasher: &mut StableHasher<W>) {
679         let ast::Ident {
680             name,
681             span,
682         } = *self;
683
684         name.hash_stable(hcx, hasher);
685         span.hash_stable(hcx, hasher);
686     }
687 }
688
689 impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItem {
690     fn hash_stable<W: StableHasherResult>(&self,
691                                           hcx: &mut StableHashingContext<'a>,
692                                           hasher: &mut StableHasher<W>) {
693         let hir::TraitItem {
694             id: _,
695             hir_id: _,
696             name,
697             ref attrs,
698             ref generics,
699             ref node,
700             span
701         } = *self;
702
703         hcx.hash_hir_item_like(|hcx| {
704             name.hash_stable(hcx, hasher);
705             attrs.hash_stable(hcx, hasher);
706             generics.hash_stable(hcx, hasher);
707             node.hash_stable(hcx, hasher);
708             span.hash_stable(hcx, hasher);
709         });
710     }
711 }
712
713 impl_stable_hash_for!(enum hir::TraitMethod {
714     Required(name),
715     Provided(body)
716 });
717
718 impl_stable_hash_for!(enum hir::TraitItemKind {
719     Const(t, body),
720     Method(sig, method),
721     Type(bounds, rhs)
722 });
723
724 impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItem {
725     fn hash_stable<W: StableHasherResult>(&self,
726                                           hcx: &mut StableHashingContext<'a>,
727                                           hasher: &mut StableHasher<W>) {
728         let hir::ImplItem {
729             id: _,
730             hir_id: _,
731             name,
732             ref vis,
733             defaultness,
734             ref attrs,
735             ref generics,
736             ref node,
737             span
738         } = *self;
739
740         hcx.hash_hir_item_like(|hcx| {
741             name.hash_stable(hcx, hasher);
742             vis.hash_stable(hcx, hasher);
743             defaultness.hash_stable(hcx, hasher);
744             attrs.hash_stable(hcx, hasher);
745             generics.hash_stable(hcx, hasher);
746             node.hash_stable(hcx, hasher);
747             span.hash_stable(hcx, hasher);
748         });
749     }
750 }
751
752 impl_stable_hash_for!(enum hir::ImplItemKind {
753     Const(t, body),
754     Method(sig, body),
755     Type(t)
756 });
757
758 impl<'a> HashStable<StableHashingContext<'a>> for hir::Visibility {
759     fn hash_stable<W: StableHasherResult>(&self,
760                                           hcx: &mut StableHashingContext<'a>,
761                                           hasher: &mut StableHasher<W>) {
762         mem::discriminant(self).hash_stable(hcx, hasher);
763         match *self {
764             hir::Visibility::Public |
765             hir::Visibility::Crate |
766             hir::Visibility::Inherited => {
767                 // No fields to hash.
768             }
769             hir::Visibility::Restricted { ref path, id } => {
770                 hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
771                     id.hash_stable(hcx, hasher);
772                 });
773                 path.hash_stable(hcx, hasher);
774             }
775         }
776     }
777 }
778
779 impl<'a> HashStable<StableHashingContext<'a>> for hir::Defaultness {
780     fn hash_stable<W: StableHasherResult>(&self,
781                                           hcx: &mut StableHashingContext<'a>,
782                                           hasher: &mut StableHasher<W>) {
783         mem::discriminant(self).hash_stable(hcx, hasher);
784         match *self {
785             hir::Defaultness::Final => {
786                 // No fields to hash.
787             }
788             hir::Defaultness::Default { has_value } => {
789                 has_value.hash_stable(hcx, hasher);
790             }
791         }
792     }
793 }
794
795 impl_stable_hash_for!(enum hir::ImplPolarity {
796     Positive,
797     Negative
798 });
799
800 impl<'a> HashStable<StableHashingContext<'a>> for hir::Mod {
801     fn hash_stable<W: StableHasherResult>(&self,
802                                           hcx: &mut StableHashingContext<'a>,
803                                           hasher: &mut StableHasher<W>) {
804         let hir::Mod {
805             inner,
806             // We are not hashing the IDs of the items contained in the module.
807             // This is harmless and matches the current behavior but it's not
808             // actually correct. See issue #40876.
809             item_ids: _,
810         } = *self;
811
812         inner.hash_stable(hcx, hasher);
813     }
814 }
815
816 impl_stable_hash_for!(struct hir::ForeignMod {
817     abi,
818     items
819 });
820
821 impl_stable_hash_for!(struct hir::EnumDef {
822     variants
823 });
824
825 impl_stable_hash_for!(struct hir::Variant_ {
826     name,
827     attrs,
828     data,
829     disr_expr
830 });
831
832 impl_stable_hash_for_spanned!(hir::Variant_);
833
834 impl_stable_hash_for!(enum hir::UseKind {
835     Single,
836     Glob,
837     ListStem
838 });
839
840 impl_stable_hash_for!(struct hir::StructField {
841     span,
842     name,
843     vis,
844     id,
845     ty,
846     attrs
847 });
848
849 impl_stable_hash_for!(enum hir::VariantData {
850     Struct(fields, id),
851     Tuple(fields, id),
852     Unit(id)
853 });
854
855 impl<'a> HashStable<StableHashingContext<'a>> for hir::Item {
856     fn hash_stable<W: StableHasherResult>(&self,
857                                           hcx: &mut StableHashingContext<'a>,
858                                           hasher: &mut StableHasher<W>) {
859         let hir::Item {
860             name,
861             ref attrs,
862             id: _,
863             hir_id: _,
864             ref node,
865             ref vis,
866             span
867         } = *self;
868
869         hcx.hash_hir_item_like(|hcx| {
870             name.hash_stable(hcx, hasher);
871             attrs.hash_stable(hcx, hasher);
872             node.hash_stable(hcx, hasher);
873             vis.hash_stable(hcx, hasher);
874             span.hash_stable(hcx, hasher);
875         });
876     }
877 }
878
879 impl_stable_hash_for!(enum hir::Item_ {
880     ItemExternCrate(orig_name),
881     ItemUse(path, use_kind),
882     ItemStatic(ty, mutability, body_id),
883     ItemConst(ty, body_id),
884     ItemFn(fn_decl, unsafety, constness, abi, generics, body_id),
885     ItemMod(module),
886     ItemForeignMod(foreign_mod),
887     ItemGlobalAsm(global_asm),
888     ItemTy(ty, generics),
889     ItemEnum(enum_def, generics),
890     ItemStruct(variant_data, generics),
891     ItemUnion(variant_data, generics),
892     ItemTrait(is_auto, unsafety, generics, bounds, item_refs),
893     ItemTraitAlias(generics, bounds),
894     ItemImpl(unsafety, impl_polarity, impl_defaultness, generics, trait_ref, ty, impl_item_refs)
895 });
896
897 impl_stable_hash_for!(struct hir::TraitItemRef {
898     id,
899     name,
900     kind,
901     span,
902     defaultness
903 });
904
905 impl_stable_hash_for!(struct hir::ImplItemRef {
906     id,
907     name,
908     kind,
909     span,
910     vis,
911     defaultness
912 });
913
914 impl<'a> HashStable<StableHashingContext<'a>>
915 for hir::AssociatedItemKind {
916     fn hash_stable<W: StableHasherResult>(&self,
917                                           hcx: &mut StableHashingContext<'a>,
918                                           hasher: &mut StableHasher<W>) {
919         mem::discriminant(self).hash_stable(hcx, hasher);
920         match *self {
921             hir::AssociatedItemKind::Const |
922             hir::AssociatedItemKind::Type => {
923                 // No fields to hash.
924             }
925             hir::AssociatedItemKind::Method { has_self } => {
926                 has_self.hash_stable(hcx, hasher);
927             }
928         }
929     }
930 }
931
932 impl_stable_hash_for!(struct hir::ForeignItem {
933     name,
934     attrs,
935     node,
936     id,
937     span,
938     vis
939 });
940
941 impl_stable_hash_for!(enum hir::ForeignItem_ {
942     ForeignItemFn(fn_decl, arg_names, generics),
943     ForeignItemStatic(ty, is_mutbl),
944     ForeignItemType
945 });
946
947 impl_stable_hash_for!(enum hir::Stmt_ {
948     StmtDecl(decl, id),
949     StmtExpr(expr, id),
950     StmtSemi(expr, id)
951 });
952
953 impl_stable_hash_for!(struct hir::Arg {
954     pat,
955     id,
956     hir_id
957 });
958
959 impl<'a> HashStable<StableHashingContext<'a>> for hir::Body {
960     fn hash_stable<W: StableHasherResult>(&self,
961                                           hcx: &mut StableHashingContext<'a>,
962                                           hasher: &mut StableHasher<W>) {
963         let hir::Body {
964             ref arguments,
965             ref value,
966             is_generator,
967         } = *self;
968
969         hcx.with_node_id_hashing_mode(NodeIdHashingMode::Ignore, |hcx| {
970             arguments.hash_stable(hcx, hasher);
971             value.hash_stable(hcx, hasher);
972             is_generator.hash_stable(hcx, hasher);
973         });
974     }
975 }
976
977 impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::BodyId {
978     type KeyType = (DefPathHash, hir::ItemLocalId);
979
980     #[inline]
981     fn to_stable_hash_key(&self,
982                           hcx: &StableHashingContext<'a>)
983                           -> (DefPathHash, hir::ItemLocalId) {
984         let hir::BodyId { node_id } = *self;
985         node_id.to_stable_hash_key(hcx)
986     }
987 }
988
989 impl_stable_hash_for!(struct hir::InlineAsmOutput {
990     constraint,
991     is_rw,
992     is_indirect
993 });
994
995 impl<'a> HashStable<StableHashingContext<'a>> for hir::GlobalAsm {
996     fn hash_stable<W: StableHasherResult>(&self,
997                                           hcx: &mut StableHashingContext<'a>,
998                                           hasher: &mut StableHasher<W>) {
999         let hir::GlobalAsm {
1000             asm,
1001             ctxt: _
1002         } = *self;
1003
1004         asm.hash_stable(hcx, hasher);
1005     }
1006 }
1007
1008 impl<'a> HashStable<StableHashingContext<'a>> for hir::InlineAsm {
1009     fn hash_stable<W: StableHasherResult>(&self,
1010                                           hcx: &mut StableHashingContext<'a>,
1011                                           hasher: &mut StableHasher<W>) {
1012         let hir::InlineAsm {
1013             asm,
1014             asm_str_style,
1015             ref outputs,
1016             ref inputs,
1017             ref clobbers,
1018             volatile,
1019             alignstack,
1020             dialect,
1021             ctxt: _, // This is used for error reporting
1022         } = *self;
1023
1024         asm.hash_stable(hcx, hasher);
1025         asm_str_style.hash_stable(hcx, hasher);
1026         outputs.hash_stable(hcx, hasher);
1027         inputs.hash_stable(hcx, hasher);
1028         clobbers.hash_stable(hcx, hasher);
1029         volatile.hash_stable(hcx, hasher);
1030         alignstack.hash_stable(hcx, hasher);
1031         dialect.hash_stable(hcx, hasher);
1032     }
1033 }
1034
1035 impl_stable_hash_for!(enum hir::def::CtorKind {
1036     Fn,
1037     Const,
1038     Fictive
1039 });
1040
1041 impl_stable_hash_for!(enum hir::def::Def {
1042     Mod(def_id),
1043     Struct(def_id),
1044     Union(def_id),
1045     Enum(def_id),
1046     Variant(def_id),
1047     Trait(def_id),
1048     TyAlias(def_id),
1049     TraitAlias(def_id),
1050     AssociatedTy(def_id),
1051     PrimTy(prim_ty),
1052     TyParam(def_id),
1053     SelfTy(trait_def_id, impl_def_id),
1054     TyForeign(def_id),
1055     Fn(def_id),
1056     Const(def_id),
1057     Static(def_id, is_mutbl),
1058     StructCtor(def_id, ctor_kind),
1059     VariantCtor(def_id, ctor_kind),
1060     Method(def_id),
1061     AssociatedConst(def_id),
1062     Local(def_id),
1063     Upvar(def_id, index, expr_id),
1064     Label(node_id),
1065     Macro(def_id, macro_kind),
1066     GlobalAsm(def_id),
1067     Err
1068 });
1069
1070 impl_stable_hash_for!(enum hir::Mutability {
1071     MutMutable,
1072     MutImmutable
1073 });
1074
1075 impl_stable_hash_for!(enum hir::IsAuto {
1076     Yes,
1077     No
1078 });
1079
1080 impl_stable_hash_for!(enum hir::Unsafety {
1081     Unsafe,
1082     Normal
1083 });
1084
1085
1086 impl_stable_hash_for!(enum hir::Constness {
1087     Const,
1088     NotConst
1089 });
1090
1091 impl<'a> HashStable<StableHashingContext<'a>>
1092 for hir::def_id::DefIndex {
1093
1094     fn hash_stable<W: StableHasherResult>(&self,
1095                                           hcx: &mut StableHashingContext<'a>,
1096                                           hasher: &mut StableHasher<W>) {
1097         hcx.local_def_path_hash(*self).hash_stable(hcx, hasher);
1098     }
1099 }
1100
1101 impl<'a> ToStableHashKey<StableHashingContext<'a>>
1102 for hir::def_id::DefIndex {
1103     type KeyType = DefPathHash;
1104
1105     #[inline]
1106     fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> DefPathHash {
1107          hcx.local_def_path_hash(*self)
1108     }
1109 }
1110
1111 impl_stable_hash_for!(struct hir::def::Export {
1112     ident,
1113     def,
1114     vis,
1115     span,
1116     is_import
1117 });
1118
1119 impl<'a> HashStable<StableHashingContext<'a>>
1120 for ::middle::lang_items::LangItem {
1121     fn hash_stable<W: StableHasherResult>(&self,
1122                                           _: &mut StableHashingContext<'a>,
1123                                           hasher: &mut StableHasher<W>) {
1124         ::std::hash::Hash::hash(self, hasher);
1125     }
1126 }
1127
1128 impl_stable_hash_for!(struct ::middle::lang_items::LanguageItems {
1129     items,
1130     missing
1131 });
1132
1133 impl<'a> HashStable<StableHashingContext<'a>>
1134 for hir::TraitCandidate {
1135     fn hash_stable<W: StableHasherResult>(&self,
1136                                           hcx: &mut StableHashingContext<'a>,
1137                                           hasher: &mut StableHasher<W>) {
1138         hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
1139             let hir::TraitCandidate {
1140                 def_id,
1141                 import_id,
1142             } = *self;
1143
1144             def_id.hash_stable(hcx, hasher);
1145             import_id.hash_stable(hcx, hasher);
1146         });
1147     }
1148 }
1149
1150 impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::TraitCandidate {
1151     type KeyType = (DefPathHash, Option<(DefPathHash, hir::ItemLocalId)>);
1152
1153     fn to_stable_hash_key(&self,
1154                           hcx: &StableHashingContext<'a>)
1155                           -> Self::KeyType {
1156         let hir::TraitCandidate {
1157             def_id,
1158             import_id,
1159         } = *self;
1160
1161         let import_id = import_id.map(|node_id| hcx.node_to_hir_id(node_id))
1162                                  .map(|hir_id| (hcx.local_def_path_hash(hir_id.owner),
1163                                                 hir_id.local_id));
1164         (hcx.def_path_hash(def_id), import_id)
1165     }
1166 }
1167
1168 impl<'hir> HashStable<StableHashingContext<'hir>> for hir::TransFnAttrs
1169 {
1170     fn hash_stable<W: StableHasherResult>(&self,
1171                                           hcx: &mut StableHashingContext<'hir>,
1172                                           hasher: &mut StableHasher<W>) {
1173         let hir::TransFnAttrs {
1174             flags,
1175             inline,
1176             export_name,
1177             ref target_features,
1178             linkage,
1179         } = *self;
1180
1181         flags.hash_stable(hcx, hasher);
1182         inline.hash_stable(hcx, hasher);
1183         export_name.hash_stable(hcx, hasher);
1184         target_features.hash_stable(hcx, hasher);
1185         linkage.hash_stable(hcx, hasher);
1186     }
1187 }
1188
1189 impl<'hir> HashStable<StableHashingContext<'hir>> for hir::TransFnAttrFlags
1190 {
1191     fn hash_stable<W: StableHasherResult>(&self,
1192                                           hcx: &mut StableHashingContext<'hir>,
1193                                           hasher: &mut StableHasher<W>) {
1194         self.bits().hash_stable(hcx, hasher);
1195     }
1196 }
1197
1198 impl<'hir> HashStable<StableHashingContext<'hir>> for attr::InlineAttr {
1199     fn hash_stable<W: StableHasherResult>(&self,
1200                                           hcx: &mut StableHashingContext<'hir>,
1201                                           hasher: &mut StableHasher<W>) {
1202         mem::discriminant(self).hash_stable(hcx, hasher);
1203     }
1204 }
1205
1206 impl_stable_hash_for!(struct hir::Freevar {
1207     def,
1208     span
1209 });