]> git.proxmox.com Git - rustc.git/blame - src/librustc/ich/impls_ty.rs
New upstream version 1.31.0~beta.4+dfsg1
[rustc.git] / src / librustc / ich / impls_ty.rs
CommitLineData
cc61c64b
XL
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 data types
12//! from rustc::ty in no particular order.
13
2c00a5a8
XL
14use ich::{Fingerprint, StableHashingContext, NodeIdHashingMode};
15use rustc_data_structures::fx::FxHashMap;
ea8adc8c
XL
16use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey,
17 StableHasher, StableHasherResult};
2c00a5a8 18use std::cell::RefCell;
cc61c64b
XL
19use std::hash as std_hash;
20use std::mem;
ea8adc8c 21use middle::region;
0531ce1d 22use infer;
ea8adc8c 23use traits;
cc61c64b 24use ty;
0531ce1d 25use mir;
cc61c64b 26
0531ce1d 27impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
b7449926 28for &'gcx ty::List<T>
0531ce1d 29 where T: HashStable<StableHashingContext<'a>> {
cc61c64b 30 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 31 hcx: &mut StableHashingContext<'a>,
cc61c64b 32 hasher: &mut StableHasher<W>) {
2c00a5a8
XL
33 thread_local! {
34 static CACHE: RefCell<FxHashMap<(usize, usize), Fingerprint>> =
0bf4aa26 35 RefCell::new(Default::default());
2c00a5a8
XL
36 }
37
38 let hash = CACHE.with(|cache| {
39 let key = (self.as_ptr() as usize, self.len());
40 if let Some(&hash) = cache.borrow().get(&key) {
41 return hash;
42 }
43
44 let mut hasher = StableHasher::new();
45 (&self[..]).hash_stable(hcx, &mut hasher);
46
47 let hash: Fingerprint = hasher.finish();
48 cache.borrow_mut().insert(key, hash);
49 hash
50 });
51
52 hash.hash_stable(hcx, hasher);
cc61c64b
XL
53 }
54}
55
b7449926 56impl<'a, 'gcx, T> ToStableHashKey<StableHashingContext<'a>> for &'gcx ty::List<T>
83c7162d
XL
57 where T: HashStable<StableHashingContext<'a>>
58{
59 type KeyType = Fingerprint;
60
61 #[inline]
62 fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> Fingerprint {
63 let mut hasher = StableHasher::new();
64 let mut hcx: StableHashingContext<'a> = hcx.clone();
65 self.hash_stable(&mut hcx, &mut hasher);
66 hasher.finish()
67 }
68}
69
70impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::subst::Kind<'gcx> {
cc61c64b 71 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d
XL
72 hcx: &mut StableHashingContext<'a>,
73 hasher: &mut StableHasher<W>) {
74 self.unpack().hash_stable(hcx, hasher);
75 }
76}
77
78impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
79for ty::subst::UnpackedKind<'gcx> {
80 fn hash_stable<W: StableHasherResult>(&self,
81 hcx: &mut StableHashingContext<'a>,
cc61c64b 82 hasher: &mut StableHasher<W>) {
83c7162d 83 mem::discriminant(self).hash_stable(hcx, hasher);
0531ce1d
XL
84 match self {
85 ty::subst::UnpackedKind::Lifetime(lt) => lt.hash_stable(hcx, hasher),
86 ty::subst::UnpackedKind::Type(ty) => ty.hash_stable(hcx, hasher),
87 }
cc61c64b
XL
88 }
89}
90
0531ce1d 91impl<'a> HashStable<StableHashingContext<'a>>
041b39d2 92for ty::RegionKind {
cc61c64b 93 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 94 hcx: &mut StableHashingContext<'a>,
cc61c64b
XL
95 hasher: &mut StableHasher<W>) {
96 mem::discriminant(self).hash_stable(hcx, hasher);
97 match *self {
98 ty::ReErased |
99 ty::ReStatic |
100 ty::ReEmpty => {
101 // No variant fields to hash for these ...
102 }
0531ce1d
XL
103 ty::ReCanonical(c) => {
104 c.hash_stable(hcx, hasher);
105 }
cc61c64b 106 ty::ReLateBound(db, ty::BrAnon(i)) => {
94b46f34 107 db.hash_stable(hcx, hasher);
cc61c64b
XL
108 i.hash_stable(hcx, hasher);
109 }
3b2f2976 110 ty::ReLateBound(db, ty::BrNamed(def_id, name)) => {
94b46f34 111 db.hash_stable(hcx, hasher);
3b2f2976
XL
112 def_id.hash_stable(hcx, hasher);
113 name.hash_stable(hcx, hasher);
114 }
ea8adc8c 115 ty::ReLateBound(db, ty::BrEnv) => {
94b46f34 116 db.hash_stable(hcx, hasher);
ea8adc8c 117 }
7cac9316
XL
118 ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index, name }) => {
119 def_id.hash_stable(hcx, hasher);
cc61c64b
XL
120 index.hash_stable(hcx, hasher);
121 name.hash_stable(hcx, hasher);
122 }
ea8adc8c
XL
123 ty::ReScope(scope) => {
124 scope.hash_stable(hcx, hasher);
cc61c64b
XL
125 }
126 ty::ReFree(ref free_region) => {
127 free_region.hash_stable(hcx, hasher);
128 }
ff7c6d11
XL
129 ty::ReClosureBound(vid) => {
130 vid.hash_stable(hcx, hasher);
131 }
cc61c64b
XL
132 ty::ReLateBound(..) |
133 ty::ReVar(..) |
0bf4aa26 134 ty::RePlaceholder(..) => {
94b46f34 135 bug!("StableHasher: unexpected region {:?}", *self)
cc61c64b
XL
136 }
137 }
138 }
139}
140
0531ce1d
XL
141impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionVid {
142 #[inline]
143 fn hash_stable<W: StableHasherResult>(&self,
144 hcx: &mut StableHashingContext<'a>,
145 hasher: &mut StableHasher<W>) {
0531ce1d
XL
146 self.index().hash_stable(hcx, hasher);
147 }
148}
149
0bf4aa26 150impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::BoundTyIndex {
ff7c6d11
XL
151 #[inline]
152 fn hash_stable<W: StableHasherResult>(&self,
153 hcx: &mut StableHashingContext<'gcx>,
154 hasher: &mut StableHasher<W>) {
ff7c6d11
XL
155 self.index().hash_stable(hcx, hasher);
156 }
157}
158
0531ce1d 159impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
3b2f2976 160for ty::adjustment::AutoBorrow<'gcx> {
cc61c64b 161 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 162 hcx: &mut StableHashingContext<'a>,
cc61c64b
XL
163 hasher: &mut StableHasher<W>) {
164 mem::discriminant(self).hash_stable(hcx, hasher);
165 match *self {
166 ty::adjustment::AutoBorrow::Ref(ref region, mutability) => {
167 region.hash_stable(hcx, hasher);
168 mutability.hash_stable(hcx, hasher);
169 }
170 ty::adjustment::AutoBorrow::RawPtr(mutability) => {
171 mutability.hash_stable(hcx, hasher);
172 }
173 }
174 }
175}
176
0531ce1d 177impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
3b2f2976 178for ty::adjustment::Adjust<'gcx> {
cc61c64b 179 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 180 hcx: &mut StableHashingContext<'a>,
cc61c64b
XL
181 hasher: &mut StableHasher<W>) {
182 mem::discriminant(self).hash_stable(hcx, hasher);
183 match *self {
184 ty::adjustment::Adjust::NeverToAny |
185 ty::adjustment::Adjust::ReifyFnPointer |
186 ty::adjustment::Adjust::UnsafeFnPointer |
187 ty::adjustment::Adjust::ClosureFnPointer |
7cac9316
XL
188 ty::adjustment::Adjust::MutToConstPointer |
189 ty::adjustment::Adjust::Unsize => {}
190 ty::adjustment::Adjust::Deref(ref overloaded) => {
191 overloaded.hash_stable(hcx, hasher);
192 }
193 ty::adjustment::Adjust::Borrow(ref autoref) => {
cc61c64b 194 autoref.hash_stable(hcx, hasher);
cc61c64b
XL
195 }
196 }
197 }
198}
199
200impl_stable_hash_for!(struct ty::adjustment::Adjustment<'tcx> { kind, target });
7cac9316 201impl_stable_hash_for!(struct ty::adjustment::OverloadedDeref<'tcx> { region, mutbl });
cc61c64b 202impl_stable_hash_for!(struct ty::UpvarBorrow<'tcx> { kind, region });
83c7162d
XL
203impl_stable_hash_for!(enum ty::adjustment::AllowTwoPhase {
204 Yes,
205 No
206});
cc61c64b 207
2c00a5a8
XL
208impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::adjustment::AutoBorrowMutability {
209 fn hash_stable<W: StableHasherResult>(&self,
210 hcx: &mut StableHashingContext<'gcx>,
211 hasher: &mut StableHasher<W>) {
212 mem::discriminant(self).hash_stable(hcx, hasher);
213 match *self {
214 ty::adjustment::AutoBorrowMutability::Mutable { ref allow_two_phase_borrow } => {
215 allow_two_phase_borrow.hash_stable(hcx, hasher);
216 }
217 ty::adjustment::AutoBorrowMutability::Immutable => {}
218 }
219 }
220}
221
ea8adc8c
XL
222impl_stable_hash_for!(struct ty::UpvarId { var_id, closure_expr_id });
223
cc61c64b
XL
224impl_stable_hash_for!(enum ty::BorrowKind {
225 ImmBorrow,
226 UniqueImmBorrow,
227 MutBorrow
228});
229
0531ce1d 230impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
3b2f2976 231for ty::UpvarCapture<'gcx> {
cc61c64b 232 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 233 hcx: &mut StableHashingContext<'a>,
cc61c64b
XL
234 hasher: &mut StableHasher<W>) {
235 mem::discriminant(self).hash_stable(hcx, hasher);
236 match *self {
237 ty::UpvarCapture::ByValue => {}
238 ty::UpvarCapture::ByRef(ref up_var_borrow) => {
239 up_var_borrow.hash_stable(hcx, hasher);
240 }
241 }
242 }
243}
244
ea8adc8c
XL
245impl_stable_hash_for!(struct ty::GenSig<'tcx> {
246 yield_ty,
247 return_ty
248});
249
cc61c64b
XL
250impl_stable_hash_for!(struct ty::FnSig<'tcx> {
251 inputs_and_output,
252 variadic,
253 unsafety,
254 abi
255});
256
0531ce1d
XL
257impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>> for ty::Binder<T>
258 where T: HashStable<StableHashingContext<'a>>
cc61c64b
XL
259{
260 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 261 hcx: &mut StableHashingContext<'a>,
cc61c64b 262 hasher: &mut StableHasher<W>) {
83c7162d 263 self.skip_binder().hash_stable(hcx, hasher);
cc61c64b
XL
264 }
265}
266
267impl_stable_hash_for!(enum ty::ClosureKind { Fn, FnMut, FnOnce });
268
269impl_stable_hash_for!(enum ty::Visibility {
270 Public,
271 Restricted(def_id),
272 Invisible
273});
274
275impl_stable_hash_for!(struct ty::TraitRef<'tcx> { def_id, substs });
276impl_stable_hash_for!(struct ty::TraitPredicate<'tcx> { trait_ref });
cc61c64b
XL
277impl_stable_hash_for!(struct ty::SubtypePredicate<'tcx> { a_is_expected, a, b });
278
0531ce1d 279impl<'a, 'gcx, A, B> HashStable<StableHashingContext<'a>>
041b39d2 280for ty::OutlivesPredicate<A, B>
0531ce1d
XL
281 where A: HashStable<StableHashingContext<'a>>,
282 B: HashStable<StableHashingContext<'a>>,
cc61c64b
XL
283{
284 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 285 hcx: &mut StableHashingContext<'a>,
cc61c64b
XL
286 hasher: &mut StableHasher<W>) {
287 let ty::OutlivesPredicate(ref a, ref b) = *self;
288 a.hash_stable(hcx, hasher);
289 b.hash_stable(hcx, hasher);
290 }
291}
292
293impl_stable_hash_for!(struct ty::ProjectionPredicate<'tcx> { projection_ty, ty });
041b39d2 294impl_stable_hash_for!(struct ty::ProjectionTy<'tcx> { substs, item_def_id });
cc61c64b
XL
295
296
0531ce1d 297impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::Predicate<'gcx> {
cc61c64b 298 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 299 hcx: &mut StableHashingContext<'a>,
cc61c64b
XL
300 hasher: &mut StableHasher<W>) {
301 mem::discriminant(self).hash_stable(hcx, hasher);
302 match *self {
303 ty::Predicate::Trait(ref pred) => {
304 pred.hash_stable(hcx, hasher);
305 }
cc61c64b
XL
306 ty::Predicate::Subtype(ref pred) => {
307 pred.hash_stable(hcx, hasher);
308 }
309 ty::Predicate::RegionOutlives(ref pred) => {
310 pred.hash_stable(hcx, hasher);
311 }
312 ty::Predicate::TypeOutlives(ref pred) => {
313 pred.hash_stable(hcx, hasher);
314 }
315 ty::Predicate::Projection(ref pred) => {
316 pred.hash_stable(hcx, hasher);
317 }
318 ty::Predicate::WellFormed(ty) => {
319 ty.hash_stable(hcx, hasher);
320 }
321 ty::Predicate::ObjectSafe(def_id) => {
322 def_id.hash_stable(hcx, hasher);
323 }
ff7c6d11 324 ty::Predicate::ClosureKind(def_id, closure_substs, closure_kind) => {
cc61c64b 325 def_id.hash_stable(hcx, hasher);
ff7c6d11 326 closure_substs.hash_stable(hcx, hasher);
cc61c64b
XL
327 closure_kind.hash_stable(hcx, hasher);
328 }
ea8adc8c
XL
329 ty::Predicate::ConstEvaluatable(def_id, substs) => {
330 def_id.hash_stable(hcx, hasher);
331 substs.hash_stable(hcx, hasher);
332 }
cc61c64b
XL
333 }
334 }
335}
336
0531ce1d 337impl<'a> HashStable<StableHashingContext<'a>> for ty::AdtFlags {
cc61c64b 338 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 339 _: &mut StableHashingContext<'a>,
cc61c64b
XL
340 hasher: &mut StableHasher<W>) {
341 std_hash::Hash::hash(self, hasher);
342 }
343}
344
b7449926
XL
345impl<'a> HashStable<StableHashingContext<'a>> for ty::VariantFlags {
346 fn hash_stable<W: StableHasherResult>(&self,
347 _: &mut StableHashingContext<'a>,
348 hasher: &mut StableHasher<W>) {
349 std_hash::Hash::hash(self, hasher);
350 }
351}
cc61c64b
XL
352
353impl_stable_hash_for!(enum ty::VariantDiscr {
354 Explicit(def_id),
355 Relative(distance)
356});
357
8faf50e0
XL
358impl_stable_hash_for!(struct ty::FieldDef {
359 did,
360 ident -> (ident.name),
361 vis,
362});
cc61c64b 363
0531ce1d 364impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
8faf50e0 365for ::mir::interpret::ConstValue<'gcx> {
cc61c64b 366 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 367 hcx: &mut StableHashingContext<'a>,
cc61c64b 368 hasher: &mut StableHasher<W>) {
8faf50e0 369 use mir::interpret::ConstValue::*;
cc61c64b
XL
370
371 mem::discriminant(self).hash_stable(hcx, hasher);
372
373 match *self {
0531ce1d 374 Unevaluated(def_id, substs) => {
cc61c64b 375 def_id.hash_stable(hcx, hasher);
0531ce1d 376 substs.hash_stable(hcx, hasher);
cc61c64b 377 }
94b46f34
XL
378 Scalar(val) => {
379 val.hash_stable(hcx, hasher);
380 }
381 ScalarPair(a, b) => {
382 a.hash_stable(hcx, hasher);
383 b.hash_stable(hcx, hasher);
384 }
b7449926
XL
385 ByRef(id, alloc, offset) => {
386 id.hash_stable(hcx, hasher);
94b46f34
XL
387 alloc.hash_stable(hcx, hasher);
388 offset.hash_stable(hcx, hasher);
389 }
390 }
391 }
392}
393
0bf4aa26
XL
394impl<'a, Tag> HashStable<StableHashingContext<'a>>
395for ::mir::interpret::Pointer<Tag>
396where Tag: HashStable<StableHashingContext<'a>>
397{
398 fn hash_stable<W: StableHasherResult>(&self,
399 hcx: &mut StableHashingContext<'a>,
400 hasher: &mut StableHasher<W>) {
401 let ::mir::interpret::Pointer { alloc_id, offset, tag } = self;
402 alloc_id.hash_stable(hcx, hasher);
403 offset.hash_stable(hcx, hasher);
404 tag.hash_stable(hcx, hasher);
405 }
406}
0531ce1d 407
0bf4aa26
XL
408impl<'a, Tag> HashStable<StableHashingContext<'a>>
409for ::mir::interpret::Scalar<Tag>
410where Tag: HashStable<StableHashingContext<'a>>
411{
412 fn hash_stable<W: StableHasherResult>(&self,
413 hcx: &mut StableHashingContext<'a>,
414 hasher: &mut StableHasher<W>) {
415 use mir::interpret::Scalar::*;
416
417 mem::discriminant(self).hash_stable(hcx, hasher);
418 match self {
419 Bits { bits, size } => {
420 bits.hash_stable(hcx, hasher);
421 size.hash_stable(hcx, hasher);
422 },
423 Ptr(ptr) => ptr.hash_stable(hcx, hasher),
424 }
425 }
426}
0531ce1d 427
0531ce1d
XL
428impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
429 fn hash_stable<W: StableHasherResult>(
430 &self,
431 hcx: &mut StableHashingContext<'a>,
432 hasher: &mut StableHasher<W>,
433 ) {
434 ty::tls::with_opt(|tcx| {
435 trace!("hashing {:?}", *self);
436 let tcx = tcx.expect("can't hash AllocIds during hir lowering");
b7449926 437 let alloc_kind = tcx.alloc_map.lock().get(*self);
94b46f34 438 alloc_kind.hash_stable(hcx, hasher);
0531ce1d
XL
439 });
440 }
441}
442
94b46f34
XL
443impl<'a, 'gcx, M: HashStable<StableHashingContext<'a>>> HashStable<StableHashingContext<'a>>
444for mir::interpret::AllocType<'gcx, M> {
445 fn hash_stable<W: StableHasherResult>(&self,
446 hcx: &mut StableHashingContext<'a>,
447 hasher: &mut StableHasher<W>) {
448 use mir::interpret::AllocType::*;
449
450 mem::discriminant(self).hash_stable(hcx, hasher);
451
452 match *self {
453 Function(instance) => instance.hash_stable(hcx, hasher),
454 Static(def_id) => def_id.hash_stable(hcx, hasher),
455 Memory(ref mem) => mem.hash_stable(hcx, hasher),
456 }
457 }
458}
459
0531ce1d
XL
460impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::Allocation {
461 fn hash_stable<W: StableHasherResult>(
462 &self,
463 hcx: &mut StableHashingContext<'a>,
464 hasher: &mut StableHasher<W>,
465 ) {
466 self.bytes.hash_stable(hcx, hasher);
467 for reloc in self.relocations.iter() {
468 reloc.hash_stable(hcx, hasher);
ea8adc8c 469 }
0531ce1d
XL
470 self.undef_mask.hash_stable(hcx, hasher);
471 self.align.hash_stable(hcx, hasher);
b7449926 472 self.mutability.hash_stable(hcx, hasher);
ea8adc8c
XL
473 }
474}
475
0531ce1d
XL
476impl_stable_hash_for!(enum ::syntax::ast::Mutability {
477 Immutable,
478 Mutable
479});
480
ea8adc8c
XL
481impl_stable_hash_for!(struct ty::Const<'tcx> {
482 ty,
483 val
484});
485
8faf50e0 486impl_stable_hash_for!(struct ::mir::interpret::ConstEvalErr<'tcx> {
ea8adc8c 487 span,
8faf50e0
XL
488 stacktrace,
489 error
ea8adc8c
XL
490});
491
8faf50e0 492impl_stable_hash_for!(struct ::mir::interpret::FrameInfo {
0531ce1d 493 span,
94b46f34 494 lint_root,
0531ce1d
XL
495 location
496});
497
cc61c64b 498impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs });
94b46f34 499impl_stable_hash_for!(struct ty::GeneratorSubsts<'tcx> { substs });
ea8adc8c 500
cc61c64b
XL
501impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
502 parent,
503 predicates
504});
505
8faf50e0 506impl_stable_hash_for!(struct ::mir::interpret::EvalError<'tcx> { kind });
83c7162d
XL
507
508impl<'a, 'gcx, O: HashStable<StableHashingContext<'a>>> HashStable<StableHashingContext<'a>>
509for ::mir::interpret::EvalErrorKind<'gcx, O> {
0531ce1d
XL
510 fn hash_stable<W: StableHasherResult>(&self,
511 hcx: &mut StableHashingContext<'a>,
512 hasher: &mut StableHasher<W>) {
513 use mir::interpret::EvalErrorKind::*;
514
83c7162d 515 mem::discriminant(&self).hash_stable(hcx, hasher);
0531ce1d 516
83c7162d 517 match *self {
b7449926 518 FunctionArgCountMismatch |
0531ce1d
XL
519 DanglingPointerDeref |
520 DoubleFree |
521 InvalidMemoryAccess |
522 InvalidFunctionPointer |
523 InvalidBool |
0531ce1d
XL
524 InvalidNullPointerUsage |
525 ReadPointerAsBytes |
526 ReadBytesAsPointer |
8faf50e0 527 ReadForeignStatic |
0531ce1d 528 InvalidPointerMath |
0531ce1d
XL
529 DeadLocal |
530 StackFrameLimitReached |
531 OutOfTls |
532 TlsOutOfBounds |
533 CalledClosureAsFunction |
534 VtableForArgumentlessMethod |
535 ModifiedConstantMemory |
536 AssumptionNotHeld |
537 InlineAsm |
538 ReallocateNonBasePtr |
539 DeallocateNonBasePtr |
540 HeapAllocZeroBytes |
541 Unreachable |
0531ce1d
XL
542 ReadFromReturnPointer |
543 UnimplementedTraitSelection |
544 TypeckError |
8faf50e0
XL
545 TooGeneric |
546 CheckMatchError |
0531ce1d
XL
547 DerefFunctionPointer |
548 ExecuteMemory |
83c7162d
XL
549 OverflowNeg |
550 RemainderByZero |
551 DivisionByZero |
552 GeneratorResumedAfterReturn |
8faf50e0
XL
553 GeneratorResumedAfterPanic |
554 InfiniteLoop => {}
b7449926
XL
555 ReadUndefBytes(offset) => offset.hash_stable(hcx, hasher),
556 InvalidDiscriminant(val) => val.hash_stable(hcx, hasher),
557 Panic { ref msg, ref file, line, col } => {
558 msg.hash_stable(hcx, hasher);
559 file.hash_stable(hcx, hasher);
560 line.hash_stable(hcx, hasher);
561 col.hash_stable(hcx, hasher);
562 },
94b46f34 563 ReferencedConstant(ref err) => err.hash_stable(hcx, hasher),
0531ce1d 564 MachineError(ref err) => err.hash_stable(hcx, hasher),
b7449926
XL
565 FunctionAbiMismatch(a, b) => {
566 a.hash_stable(hcx, hasher);
567 b.hash_stable(hcx, hasher)
568 },
569 FunctionArgMismatch(a, b) => {
0531ce1d
XL
570 a.hash_stable(hcx, hasher);
571 b.hash_stable(hcx, hasher)
572 },
0bf4aa26
XL
573 FunctionRetMismatch(a, b) => {
574 a.hash_stable(hcx, hasher);
575 b.hash_stable(hcx, hasher)
576 },
0531ce1d
XL
577 NoMirFor(ref s) => s.hash_stable(hcx, hasher),
578 UnterminatedCString(ptr) => ptr.hash_stable(hcx, hasher),
579 PointerOutOfBounds {
580 ptr,
581 access,
582 allocation_size,
583 } => {
584 ptr.hash_stable(hcx, hasher);
585 access.hash_stable(hcx, hasher);
586 allocation_size.hash_stable(hcx, hasher)
587 },
588 InvalidBoolOp(bop) => bop.hash_stable(hcx, hasher),
589 Unimplemented(ref s) => s.hash_stable(hcx, hasher),
83c7162d
XL
590 BoundsCheck { ref len, ref index } => {
591 len.hash_stable(hcx, hasher);
592 index.hash_stable(hcx, hasher)
0531ce1d
XL
593 },
594 Intrinsic(ref s) => s.hash_stable(hcx, hasher),
595 InvalidChar(c) => c.hash_stable(hcx, hasher),
596 AbiViolation(ref s) => s.hash_stable(hcx, hasher),
597 AlignmentCheckFailed {
598 required,
599 has,
600 } => {
601 required.hash_stable(hcx, hasher);
602 has.hash_stable(hcx, hasher)
603 },
604 MemoryLockViolation {
605 ptr,
606 len,
607 frame,
608 access,
609 ref lock,
610 } => {
611 ptr.hash_stable(hcx, hasher);
612 len.hash_stable(hcx, hasher);
613 frame.hash_stable(hcx, hasher);
614 access.hash_stable(hcx, hasher);
615 lock.hash_stable(hcx, hasher)
616 },
617 MemoryAcquireConflict {
618 ptr,
619 len,
620 kind,
621 ref lock,
622 } => {
623 ptr.hash_stable(hcx, hasher);
624 len.hash_stable(hcx, hasher);
625 kind.hash_stable(hcx, hasher);
626 lock.hash_stable(hcx, hasher)
627 },
628 InvalidMemoryLockRelease {
629 ptr,
630 len,
631 frame,
632 ref lock,
633 } => {
634 ptr.hash_stable(hcx, hasher);
635 len.hash_stable(hcx, hasher);
636 frame.hash_stable(hcx, hasher);
637 lock.hash_stable(hcx, hasher)
638 },
639 DeallocatedLockedMemory {
640 ptr,
641 ref lock,
642 } => {
643 ptr.hash_stable(hcx, hasher);
644 lock.hash_stable(hcx, hasher)
645 },
646 ValidationFailure(ref s) => s.hash_stable(hcx, hasher),
647 TypeNotPrimitive(ty) => ty.hash_stable(hcx, hasher),
648 ReallocatedWrongMemoryKind(ref a, ref b) => {
649 a.hash_stable(hcx, hasher);
650 b.hash_stable(hcx, hasher)
651 },
652 DeallocatedWrongMemoryKind(ref a, ref b) => {
653 a.hash_stable(hcx, hasher);
654 b.hash_stable(hcx, hasher)
655 },
656 IncorrectAllocationInformation(a, b, c, d) => {
657 a.hash_stable(hcx, hasher);
658 b.hash_stable(hcx, hasher);
659 c.hash_stable(hcx, hasher);
660 d.hash_stable(hcx, hasher)
661 },
662 Layout(lay) => lay.hash_stable(hcx, hasher),
663 HeapAllocNonPowerOfTwoAlignment(n) => n.hash_stable(hcx, hasher),
664 PathNotFound(ref v) => v.hash_stable(hcx, hasher),
83c7162d 665 Overflow(op) => op.hash_stable(hcx, hasher),
0531ce1d
XL
666 }
667 }
668}
669
670impl_stable_hash_for!(enum mir::interpret::Lock {
671 NoLock,
672 WriteLock(dl),
673 ReadLock(v)
674});
675
676impl_stable_hash_for!(struct mir::interpret::DynamicLifetime {
677 frame,
678 region
679});
680
681impl_stable_hash_for!(enum mir::interpret::AccessKind {
682 Read,
683 Write
684});
685
cc61c64b
XL
686impl_stable_hash_for!(enum ty::Variance {
687 Covariant,
688 Invariant,
689 Contravariant,
690 Bivariant
691});
692
693impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized {
694 Struct(index)
695});
696
8faf50e0
XL
697impl_stable_hash_for!(struct ty::Generics {
698 parent,
699 parent_count,
700 params,
701 // Reverse map to each param's `index` field, from its `def_id`.
702 param_def_id_to_index -> _, // Don't hash this
703 has_self,
704 has_late_bound_regions,
705});
cc61c64b 706
94b46f34 707impl_stable_hash_for!(struct ty::GenericParamDef {
cc61c64b
XL
708 name,
709 def_id,
710 index,
ea8adc8c 711 pure_wrt_drop,
94b46f34 712 kind
cc61c64b
XL
713});
714
94b46f34
XL
715impl<'a> HashStable<StableHashingContext<'a>> for ty::GenericParamDefKind {
716 fn hash_stable<W: StableHasherResult>(&self,
717 hcx: &mut StableHashingContext<'a>,
718 hasher: &mut StableHasher<W>) {
719 mem::discriminant(self).hash_stable(hcx, hasher);
720 match *self {
721 ty::GenericParamDefKind::Lifetime => {}
722 ty::GenericParamDefKind::Type {
723 has_default,
724 ref object_lifetime_default,
725 ref synthetic,
726 } => {
727 has_default.hash_stable(hcx, hasher);
728 object_lifetime_default.hash_stable(hcx, hasher);
729 synthetic.hash_stable(hcx, hasher);
730 }
731 }
732 }
733}
734
0531ce1d 735impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
cc61c64b 736for ::middle::resolve_lifetime::Set1<T>
0531ce1d 737 where T: HashStable<StableHashingContext<'a>>
cc61c64b
XL
738{
739 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 740 hcx: &mut StableHashingContext<'a>,
cc61c64b
XL
741 hasher: &mut StableHasher<W>) {
742 use middle::resolve_lifetime::Set1;
743
744 mem::discriminant(self).hash_stable(hcx, hasher);
745 match *self {
746 Set1::Empty |
747 Set1::Many => {
748 // Nothing to do.
749 }
750 Set1::One(ref value) => {
751 value.hash_stable(hcx, hasher);
752 }
753 }
754 }
755}
756
ff7c6d11 757impl_stable_hash_for!(enum ::middle::resolve_lifetime::LifetimeDefOrigin {
0bf4aa26
XL
758 ExplicitOrElided,
759 InBand,
760 Error,
ff7c6d11
XL
761});
762
cc61c64b
XL
763impl_stable_hash_for!(enum ::middle::resolve_lifetime::Region {
764 Static,
ff7c6d11
XL
765 EarlyBound(index, decl, is_in_band),
766 LateBound(db_index, decl, is_in_band),
cc61c64b
XL
767 LateBoundAnon(db_index, anon_index),
768 Free(call_site_scope_data, decl)
769});
770
cc61c64b
XL
771impl_stable_hash_for!(enum ty::cast::CastKind {
772 CoercionCast,
773 PtrPtrCast,
774 PtrAddrCast,
775 AddrPtrCast,
776 NumericCast,
777 EnumCast,
778 PrimIntCast,
779 U8CharCast,
780 ArrayPtrCast,
781 FnPtrPtrCast,
782 FnPtrAddrCast
783});
784
b7449926
XL
785impl_stable_hash_for!(struct ::middle::region::Scope { id, data });
786
787impl_stable_hash_for!(enum ::middle::region::ScopeData {
788 Node,
789 CallSite,
790 Arguments,
791 Destruction,
792 Remainder(first_statement_index)
793});
cc61c64b 794
0531ce1d 795impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
ea8adc8c
XL
796 type KeyType = region::Scope;
797
798 #[inline]
0531ce1d 799 fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> region::Scope {
ea8adc8c 800 *self
cc61c64b
XL
801 }
802}
803
cc61c64b
XL
804impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
805 custom_kind
806});
807
808impl_stable_hash_for!(struct ty::FreeRegion {
809 scope,
810 bound_region
811});
812
813impl_stable_hash_for!(enum ty::BoundRegion {
814 BrAnon(index),
815 BrNamed(def_id, name),
816 BrFresh(index),
817 BrEnv
818});
819
0531ce1d 820impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
b7449926 821for ty::TyKind<'gcx>
cc61c64b
XL
822{
823 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 824 hcx: &mut StableHashingContext<'a>,
cc61c64b 825 hasher: &mut StableHasher<W>) {
b7449926 826 use ty::TyKind::*;
cc61c64b
XL
827
828 mem::discriminant(self).hash_stable(hcx, hasher);
829 match *self {
b7449926
XL
830 Bool |
831 Char |
832 Str |
833 Error |
834 Never => {
cc61c64b
XL
835 // Nothing more to hash.
836 }
b7449926 837 Int(int_ty) => {
cc61c64b
XL
838 int_ty.hash_stable(hcx, hasher);
839 }
b7449926 840 Uint(uint_ty) => {
cc61c64b
XL
841 uint_ty.hash_stable(hcx, hasher);
842 }
b7449926 843 Float(float_ty) => {
cc61c64b
XL
844 float_ty.hash_stable(hcx, hasher);
845 }
b7449926 846 Adt(adt_def, substs) => {
cc61c64b
XL
847 adt_def.hash_stable(hcx, hasher);
848 substs.hash_stable(hcx, hasher);
849 }
b7449926 850 Array(inner_ty, len) => {
cc61c64b
XL
851 inner_ty.hash_stable(hcx, hasher);
852 len.hash_stable(hcx, hasher);
853 }
b7449926 854 Slice(inner_ty) => {
cc61c64b
XL
855 inner_ty.hash_stable(hcx, hasher);
856 }
b7449926 857 RawPtr(pointee_ty) => {
cc61c64b
XL
858 pointee_ty.hash_stable(hcx, hasher);
859 }
b7449926 860 Ref(region, pointee_ty, mutbl) => {
cc61c64b
XL
861 region.hash_stable(hcx, hasher);
862 pointee_ty.hash_stable(hcx, hasher);
94b46f34 863 mutbl.hash_stable(hcx, hasher);
cc61c64b 864 }
b7449926 865 FnDef(def_id, substs) => {
cc61c64b
XL
866 def_id.hash_stable(hcx, hasher);
867 substs.hash_stable(hcx, hasher);
cc61c64b 868 }
b7449926 869 FnPtr(ref sig) => {
cc61c64b
XL
870 sig.hash_stable(hcx, hasher);
871 }
b7449926 872 Dynamic(ref existential_predicates, region) => {
cc61c64b
XL
873 existential_predicates.hash_stable(hcx, hasher);
874 region.hash_stable(hcx, hasher);
875 }
b7449926 876 Closure(def_id, closure_substs) => {
cc61c64b
XL
877 def_id.hash_stable(hcx, hasher);
878 closure_substs.hash_stable(hcx, hasher);
879 }
b7449926 880 Generator(def_id, generator_substs, movability) => {
ea8adc8c 881 def_id.hash_stable(hcx, hasher);
94b46f34
XL
882 generator_substs.hash_stable(hcx, hasher);
883 movability.hash_stable(hcx, hasher);
ea8adc8c 884 }
b7449926 885 GeneratorWitness(types) => {
2c00a5a8
XL
886 types.hash_stable(hcx, hasher)
887 }
b7449926 888 Tuple(inner_tys) => {
cc61c64b 889 inner_tys.hash_stable(hcx, hasher);
cc61c64b 890 }
0bf4aa26
XL
891 Projection(ref data) | UnnormalizedProjection(ref data) => {
892 data.hash_stable(hcx, hasher);
cc61c64b 893 }
b7449926 894 Opaque(def_id, substs) => {
cc61c64b
XL
895 def_id.hash_stable(hcx, hasher);
896 substs.hash_stable(hcx, hasher);
897 }
b7449926 898 Param(param_ty) => {
cc61c64b
XL
899 param_ty.hash_stable(hcx, hasher);
900 }
b7449926 901 Foreign(def_id) => {
abe05a73
XL
902 def_id.hash_stable(hcx, hasher);
903 }
b7449926 904 Infer(infer_ty) => {
0531ce1d 905 infer_ty.hash_stable(hcx, hasher);
cc61c64b
XL
906 }
907 }
908 }
909}
910
0531ce1d
XL
911impl_stable_hash_for!(enum ty::InferTy {
912 TyVar(a),
913 IntVar(a),
914 FloatVar(a),
915 FreshTy(a),
916 FreshIntTy(a),
917 FreshFloatTy(a),
0bf4aa26 918 BoundTy(a),
0531ce1d
XL
919});
920
921impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
922for ty::TyVid
923{
924 fn hash_stable<W: StableHasherResult>(&self,
925 _hcx: &mut StableHashingContext<'a>,
926 _hasher: &mut StableHasher<W>) {
927 // TyVid values are confined to an inference context and hence
928 // should not be hashed.
b7449926 929 bug!("ty::TyKind::hash_stable() - can't hash a TyVid {:?}.", *self)
0531ce1d
XL
930 }
931}
932
933impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
934for ty::IntVid
935{
936 fn hash_stable<W: StableHasherResult>(&self,
937 _hcx: &mut StableHashingContext<'a>,
938 _hasher: &mut StableHasher<W>) {
939 // IntVid values are confined to an inference context and hence
940 // should not be hashed.
b7449926 941 bug!("ty::TyKind::hash_stable() - can't hash an IntVid {:?}.", *self)
0531ce1d
XL
942 }
943}
944
945impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
946for ty::FloatVid
947{
948 fn hash_stable<W: StableHasherResult>(&self,
949 _hcx: &mut StableHashingContext<'a>,
950 _hasher: &mut StableHasher<W>) {
951 // FloatVid values are confined to an inference context and hence
952 // should not be hashed.
b7449926 953 bug!("ty::TyKind::hash_stable() - can't hash a FloatVid {:?}.", *self)
0531ce1d
XL
954 }
955}
956
cc61c64b
XL
957impl_stable_hash_for!(struct ty::ParamTy {
958 idx,
959 name
960});
961
962impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> {
963 ty,
964 mutbl
965});
966
0531ce1d 967impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
3b2f2976 968for ty::ExistentialPredicate<'gcx>
cc61c64b
XL
969{
970 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 971 hcx: &mut StableHashingContext<'a>,
cc61c64b
XL
972 hasher: &mut StableHasher<W>) {
973 mem::discriminant(self).hash_stable(hcx, hasher);
974 match *self {
975 ty::ExistentialPredicate::Trait(ref trait_ref) => {
976 trait_ref.hash_stable(hcx, hasher);
977 }
978 ty::ExistentialPredicate::Projection(ref projection) => {
979 projection.hash_stable(hcx, hasher);
980 }
981 ty::ExistentialPredicate::AutoTrait(def_id) => {
982 def_id.hash_stable(hcx, hasher);
983 }
984 }
985 }
986}
987
988impl_stable_hash_for!(struct ty::ExistentialTraitRef<'tcx> {
989 def_id,
990 substs
991});
992
993impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> {
041b39d2
XL
994 item_def_id,
995 substs,
cc61c64b
XL
996 ty
997});
998
041b39d2
XL
999impl_stable_hash_for!(struct ty::Instance<'tcx> {
1000 def,
1001 substs
1002});
1003
0531ce1d 1004impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::InstanceDef<'gcx> {
041b39d2 1005 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 1006 hcx: &mut StableHashingContext<'a>,
041b39d2
XL
1007 hasher: &mut StableHasher<W>) {
1008 mem::discriminant(self).hash_stable(hcx, hasher);
1009
1010 match *self {
1011 ty::InstanceDef::Item(def_id) => {
1012 def_id.hash_stable(hcx, hasher);
1013 }
1014 ty::InstanceDef::Intrinsic(def_id) => {
1015 def_id.hash_stable(hcx, hasher);
1016 }
1017 ty::InstanceDef::FnPtrShim(def_id, ty) => {
1018 def_id.hash_stable(hcx, hasher);
1019 ty.hash_stable(hcx, hasher);
1020 }
1021 ty::InstanceDef::Virtual(def_id, n) => {
1022 def_id.hash_stable(hcx, hasher);
1023 n.hash_stable(hcx, hasher);
1024 }
1025 ty::InstanceDef::ClosureOnceShim { call_once } => {
1026 call_once.hash_stable(hcx, hasher);
1027 }
0531ce1d 1028 ty::InstanceDef::DropGlue(def_id, ty) => {
041b39d2 1029 def_id.hash_stable(hcx, hasher);
0531ce1d 1030 ty.hash_stable(hcx, hasher);
041b39d2 1031 }
0531ce1d 1032 ty::InstanceDef::CloneShim(def_id, ty) => {
3b2f2976 1033 def_id.hash_stable(hcx, hasher);
0531ce1d 1034 ty.hash_stable(hcx, hasher);
3b2f2976 1035 }
041b39d2
XL
1036 }
1037 }
1038}
1039
8faf50e0
XL
1040impl_stable_hash_for!(struct ty::TraitDef {
1041 // We already have the def_path_hash below, no need to hash it twice
1042 def_id -> _,
1043 unsafety,
1044 paren_sugar,
1045 has_auto_impl,
0bf4aa26 1046 is_marker,
8faf50e0
XL
1047 def_path_hash,
1048});
ea8adc8c
XL
1049
1050impl_stable_hash_for!(struct ty::Destructor {
1051 did
1052});
1053
8faf50e0
XL
1054impl_stable_hash_for!(struct ty::CrateVariancesMap {
1055 variances,
1056 // This is just an irrelevant helper value.
1057 empty_variance -> _,
1058});
83c7162d 1059
8faf50e0
XL
1060impl_stable_hash_for!(struct ty::CratePredicatesMap<'tcx> {
1061 predicates,
1062 // This is just an irrelevant helper value.
1063 empty_predicate -> _,
1064});
83c7162d 1065
ea8adc8c
XL
1066impl_stable_hash_for!(struct ty::AssociatedItem {
1067 def_id,
8faf50e0 1068 ident -> (ident.name),
ea8adc8c
XL
1069 kind,
1070 vis,
1071 defaultness,
1072 container,
1073 method_has_self_argument
1074});
1075
1076impl_stable_hash_for!(enum ty::AssociatedKind {
1077 Const,
1078 Method,
8faf50e0 1079 Existential,
ea8adc8c
XL
1080 Type
1081});
1082
1083impl_stable_hash_for!(enum ty::AssociatedItemContainer {
1084 TraitContainer(def_id),
1085 ImplContainer(def_id)
1086});
1087
1088
0531ce1d 1089impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
ea8adc8c 1090for ty::steal::Steal<T>
0531ce1d 1091 where T: HashStable<StableHashingContext<'a>>
ea8adc8c
XL
1092{
1093 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 1094 hcx: &mut StableHashingContext<'a>,
ea8adc8c
XL
1095 hasher: &mut StableHasher<W>) {
1096 self.borrow().hash_stable(hcx, hasher);
1097 }
1098}
1099
1100impl_stable_hash_for!(struct ty::ParamEnv<'tcx> {
1101 caller_bounds,
1102 reveal
1103});
1104
1105impl_stable_hash_for!(enum traits::Reveal {
1106 UserFacing,
1107 All
1108});
1109
1110impl_stable_hash_for!(enum ::middle::privacy::AccessLevel {
b7449926 1111 ReachableFromImplTrait,
ea8adc8c
XL
1112 Reachable,
1113 Exported,
1114 Public
1115});
1116
0531ce1d 1117impl<'a> HashStable<StableHashingContext<'a>>
ea8adc8c
XL
1118for ::middle::privacy::AccessLevels {
1119 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 1120 hcx: &mut StableHashingContext<'a>,
ea8adc8c
XL
1121 hasher: &mut StableHasher<W>) {
1122 hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
1123 let ::middle::privacy::AccessLevels {
1124 ref map
1125 } = *self;
1126
1127 map.hash_stable(hcx, hasher);
1128 });
1129 }
1130}
1131
1132impl_stable_hash_for!(struct ty::CrateInherentImpls {
1133 inherent_impls
1134});
1135
1136impl_stable_hash_for!(enum ::session::CompileIncomplete {
1137 Stopped,
1138 Errored(error_reported)
1139});
1140
1141impl_stable_hash_for!(struct ::util::common::ErrorReported {});
1142
1143impl_stable_hash_for!(tuple_struct ::middle::reachable::ReachableSet {
1144 reachable_set
1145});
abe05a73 1146
0531ce1d
XL
1147impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1148for traits::Vtable<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
abe05a73 1149 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 1150 hcx: &mut StableHashingContext<'a>,
abe05a73
XL
1151 hasher: &mut StableHasher<W>) {
1152 use traits::Vtable::*;
1153
1154 mem::discriminant(self).hash_stable(hcx, hasher);
1155
1156 match self {
1157 &VtableImpl(ref table_impl) => table_impl.hash_stable(hcx, hasher),
1158 &VtableAutoImpl(ref table_def_impl) => table_def_impl.hash_stable(hcx, hasher),
1159 &VtableParam(ref table_param) => table_param.hash_stable(hcx, hasher),
1160 &VtableObject(ref table_obj) => table_obj.hash_stable(hcx, hasher),
1161 &VtableBuiltin(ref table_builtin) => table_builtin.hash_stable(hcx, hasher),
1162 &VtableClosure(ref table_closure) => table_closure.hash_stable(hcx, hasher),
1163 &VtableFnPointer(ref table_fn_pointer) => table_fn_pointer.hash_stable(hcx, hasher),
1164 &VtableGenerator(ref table_generator) => table_generator.hash_stable(hcx, hasher),
1165 }
1166 }
1167}
1168
0531ce1d
XL
1169impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1170for traits::VtableImplData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
abe05a73 1171 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 1172 hcx: &mut StableHashingContext<'a>,
abe05a73
XL
1173 hasher: &mut StableHasher<W>) {
1174 let traits::VtableImplData {
1175 impl_def_id,
1176 substs,
1177 ref nested,
1178 } = *self;
1179 impl_def_id.hash_stable(hcx, hasher);
1180 substs.hash_stable(hcx, hasher);
1181 nested.hash_stable(hcx, hasher);
1182 }
1183}
1184
0531ce1d
XL
1185impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1186for traits::VtableAutoImplData<N> where N: HashStable<StableHashingContext<'a>> {
abe05a73 1187 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 1188 hcx: &mut StableHashingContext<'a>,
abe05a73
XL
1189 hasher: &mut StableHasher<W>) {
1190 let traits::VtableAutoImplData {
1191 trait_def_id,
1192 ref nested,
1193 } = *self;
1194 trait_def_id.hash_stable(hcx, hasher);
1195 nested.hash_stable(hcx, hasher);
1196 }
1197}
1198
0531ce1d
XL
1199impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1200for traits::VtableObjectData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
abe05a73 1201 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 1202 hcx: &mut StableHashingContext<'a>,
abe05a73
XL
1203 hasher: &mut StableHasher<W>) {
1204 let traits::VtableObjectData {
1205 upcast_trait_ref,
1206 vtable_base,
1207 ref nested,
1208 } = *self;
1209 upcast_trait_ref.hash_stable(hcx, hasher);
1210 vtable_base.hash_stable(hcx, hasher);
1211 nested.hash_stable(hcx, hasher);
1212 }
1213}
1214
0531ce1d
XL
1215impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1216for traits::VtableBuiltinData<N> where N: HashStable<StableHashingContext<'a>> {
abe05a73 1217 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 1218 hcx: &mut StableHashingContext<'a>,
abe05a73
XL
1219 hasher: &mut StableHasher<W>) {
1220 let traits::VtableBuiltinData {
1221 ref nested,
1222 } = *self;
1223 nested.hash_stable(hcx, hasher);
1224 }
1225}
1226
0531ce1d
XL
1227impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1228for traits::VtableClosureData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
abe05a73 1229 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 1230 hcx: &mut StableHashingContext<'a>,
abe05a73
XL
1231 hasher: &mut StableHasher<W>) {
1232 let traits::VtableClosureData {
1233 closure_def_id,
1234 substs,
1235 ref nested,
1236 } = *self;
1237 closure_def_id.hash_stable(hcx, hasher);
1238 substs.hash_stable(hcx, hasher);
1239 nested.hash_stable(hcx, hasher);
1240 }
1241}
1242
0531ce1d
XL
1243impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1244for traits::VtableFnPointerData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
abe05a73 1245 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 1246 hcx: &mut StableHashingContext<'a>,
abe05a73
XL
1247 hasher: &mut StableHasher<W>) {
1248 let traits::VtableFnPointerData {
1249 fn_ty,
1250 ref nested,
1251 } = *self;
1252 fn_ty.hash_stable(hcx, hasher);
1253 nested.hash_stable(hcx, hasher);
1254 }
1255}
1256
0531ce1d
XL
1257impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1258for traits::VtableGeneratorData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
abe05a73 1259 fn hash_stable<W: StableHasherResult>(&self,
0531ce1d 1260 hcx: &mut StableHashingContext<'a>,
abe05a73
XL
1261 hasher: &mut StableHasher<W>) {
1262 let traits::VtableGeneratorData {
94b46f34 1263 generator_def_id,
abe05a73
XL
1264 substs,
1265 ref nested,
1266 } = *self;
94b46f34 1267 generator_def_id.hash_stable(hcx, hasher);
abe05a73
XL
1268 substs.hash_stable(hcx, hasher);
1269 nested.hash_stable(hcx, hasher);
1270 }
1271}
0531ce1d
XL
1272
1273impl_stable_hash_for!(
1274 impl<'tcx, V> for struct infer::canonical::Canonical<'tcx, V> {
1275 variables, value
1276 }
1277);
1278
1279impl_stable_hash_for!(
1280 impl<'tcx> for struct infer::canonical::CanonicalVarValues<'tcx> {
1281 var_values
1282 }
1283);
1284
1285impl_stable_hash_for!(struct infer::canonical::CanonicalVarInfo {
1286 kind
1287});
1288
1289impl_stable_hash_for!(enum infer::canonical::CanonicalVarKind {
1290 Ty(k),
1291 Region
1292});
1293
1294impl_stable_hash_for!(enum infer::canonical::CanonicalTyVarKind {
1295 General,
1296 Int,
1297 Float
1298});
1299
1300impl_stable_hash_for!(
0bf4aa26 1301 impl<'tcx, R> for struct infer::canonical::QueryResponse<'tcx, R> {
0531ce1d
XL
1302 var_values, region_constraints, certainty, value
1303 }
1304);
1305
0531ce1d
XL
1306impl_stable_hash_for!(enum infer::canonical::Certainty {
1307 Proven, Ambiguous
1308});
1309
8faf50e0 1310impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WhereClause<'tcx> {
0531ce1d
XL
1311 fn hash_stable<W: StableHasherResult>(&self,
1312 hcx: &mut StableHashingContext<'a>,
1313 hasher: &mut StableHasher<W>) {
8faf50e0 1314 use traits::WhereClause::*;
0531ce1d
XL
1315
1316 mem::discriminant(self).hash_stable(hcx, hasher);
1317 match self {
1318 Implemented(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1319 ProjectionEq(projection) => projection.hash_stable(hcx, hasher),
8faf50e0
XL
1320 TypeOutlives(ty_outlives) => ty_outlives.hash_stable(hcx, hasher),
1321 RegionOutlives(region_outlives) => region_outlives.hash_stable(hcx, hasher),
1322 }
1323 }
1324}
1325
1326impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WellFormed<'tcx> {
1327 fn hash_stable<W: StableHasherResult>(&self,
1328 hcx: &mut StableHashingContext<'a>,
1329 hasher: &mut StableHasher<W>) {
1330 use traits::WellFormed::*;
1331
1332 mem::discriminant(self).hash_stable(hcx, hasher);
1333 match self {
1334 Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1335 Ty(ty) => ty.hash_stable(hcx, hasher),
1336 }
1337 }
1338}
1339
1340impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::FromEnv<'tcx> {
1341 fn hash_stable<W: StableHasherResult>(&self,
1342 hcx: &mut StableHashingContext<'a>,
1343 hasher: &mut StableHasher<W>) {
1344 use traits::FromEnv::*;
1345
1346 mem::discriminant(self).hash_stable(hcx, hasher);
1347 match self {
1348 Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1349 Ty(ty) => ty.hash_stable(hcx, hasher),
0531ce1d
XL
1350 }
1351 }
1352}
1353
1354impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::DomainGoal<'tcx> {
1355 fn hash_stable<W: StableHasherResult>(&self,
1356 hcx: &mut StableHashingContext<'a>,
1357 hasher: &mut StableHasher<W>) {
1358 use traits::DomainGoal::*;
1359
1360 mem::discriminant(self).hash_stable(hcx, hasher);
1361 match self {
8faf50e0
XL
1362 Holds(wc) => wc.hash_stable(hcx, hasher),
1363 WellFormed(wf) => wf.hash_stable(hcx, hasher),
1364 FromEnv(from_env) => from_env.hash_stable(hcx, hasher),
83c7162d 1365 Normalize(projection) => projection.hash_stable(hcx, hasher),
0531ce1d
XL
1366 }
1367 }
1368}
1369
1370impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
1371 fn hash_stable<W: StableHasherResult>(&self,
1372 hcx: &mut StableHashingContext<'a>,
1373 hasher: &mut StableHasher<W>) {
0bf4aa26 1374 use traits::GoalKind::*;
0531ce1d
XL
1375
1376 mem::discriminant(self).hash_stable(hcx, hasher);
1377 match self {
1378 Implies(hypotheses, goal) => {
1379 hypotheses.hash_stable(hcx, hasher);
1380 goal.hash_stable(hcx, hasher);
1381 },
1382 And(goal1, goal2) => {
1383 goal1.hash_stable(hcx, hasher);
1384 goal2.hash_stable(hcx, hasher);
1385 }
1386 Not(goal) => goal.hash_stable(hcx, hasher),
1387 DomainGoal(domain_goal) => domain_goal.hash_stable(hcx, hasher),
1388 Quantified(quantifier, goal) => {
1389 quantifier.hash_stable(hcx, hasher);
1390 goal.hash_stable(hcx, hasher);
1391 },
83c7162d 1392 CannotProve => { },
0531ce1d
XL
1393 }
1394 }
1395}
1396
83c7162d
XL
1397impl_stable_hash_for!(
1398 impl<'tcx> for struct traits::ProgramClause<'tcx> {
0bf4aa26 1399 goal, hypotheses, category
83c7162d
XL
1400 }
1401);
1402
0bf4aa26
XL
1403impl_stable_hash_for!(enum traits::ProgramClauseCategory {
1404 ImpliedBound,
1405 WellFormed,
1406 Other,
1407});
1408
0531ce1d
XL
1409impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Clause<'tcx> {
1410 fn hash_stable<W: StableHasherResult>(&self,
1411 hcx: &mut StableHashingContext<'a>,
1412 hasher: &mut StableHasher<W>) {
1413 use traits::Clause::*;
1414
1415 mem::discriminant(self).hash_stable(hcx, hasher);
1416 match self {
83c7162d 1417 Implies(clause) => clause.hash_stable(hcx, hasher),
0531ce1d
XL
1418 ForAll(clause) => clause.hash_stable(hcx, hasher),
1419 }
1420 }
1421}
1422
1423impl_stable_hash_for!(enum traits::QuantifierKind {
1424 Universal,
1425 Existential
1426});
0bf4aa26
XL
1427
1428impl_stable_hash_for!(struct ty::subst::UserSubsts<'tcx> { substs, user_self_ty });
1429
1430impl_stable_hash_for!(struct ty::subst::UserSelfTy<'tcx> { impl_def_id, self_ty });
1431
1432impl_stable_hash_for!(
1433 impl<'tcx> for struct traits::Environment<'tcx> {
1434 clauses,
1435 }
1436);