Differences From
Artifact [258f90e5ef]:
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 1 //! This module contains `HashStable` implementations for various data types
12 2 //! from rustc::ty in no particular order.
13 3
14 -use ich::{self, StableHashingContext, NodeIdHashingMode};
15 -use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
16 - StableHasherResult};
17 -use std::hash as std_hash;
4 +use crate::ich::{Fingerprint, StableHashingContext, NodeIdHashingMode};
5 +use rustc_data_structures::fx::FxHashMap;
6 +use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher};
7 +use std::cell::RefCell;
18 8 use std::mem;
19 -use syntax_pos::symbol::InternedString;
20 -use ty;
21 -
22 -impl_stable_hash_for!(struct ty::ItemSubsts<'tcx> { substs });
23 -
24 -impl<'a, 'tcx, T> HashStable<StableHashingContext<'a, 'tcx>> for &'tcx ty::Slice<T>
25 - where T: HashStable<StableHashingContext<'a, 'tcx>> {
26 - fn hash_stable<W: StableHasherResult>(&self,
27 - hcx: &mut StableHashingContext<'a, 'tcx>,
28 - hasher: &mut StableHasher<W>) {
29 - (&self[..]).hash_stable(hcx, hasher);
30 - }
31 -}
32 -
33 -impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::subst::Kind<'tcx> {
34 - fn hash_stable<W: StableHasherResult>(&self,
35 - hcx: &mut StableHashingContext<'a, 'tcx>,
36 - hasher: &mut StableHasher<W>) {
37 - self.as_type().hash_stable(hcx, hasher);
38 - self.as_region().hash_stable(hcx, hasher);
39 - }
40 -}
41 -
42 -impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::RegionKind {
43 - fn hash_stable<W: StableHasherResult>(&self,
44 - hcx: &mut StableHashingContext<'a, 'tcx>,
45 - hasher: &mut StableHasher<W>) {
9 +use crate::middle::region;
10 +use crate::ty;
11 +use crate::mir;
12 +
13 +impl<'a, 'tcx, T> HashStable<StableHashingContext<'a>> for &'tcx ty::List<T>
14 +where
15 + T: HashStable<StableHashingContext<'a>>,
16 +{
17 + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
18 + thread_local! {
19 + static CACHE: RefCell<FxHashMap<(usize, usize), Fingerprint>> =
20 + RefCell::new(Default::default());
21 + }
22 +
23 + let hash = CACHE.with(|cache| {
24 + let key = (self.as_ptr() as usize, self.len());
25 + if let Some(&hash) = cache.borrow().get(&key) {
26 + return hash;
27 + }
28 +
29 + let mut hasher = StableHasher::new();
30 + (&self[..]).hash_stable(hcx, &mut hasher);
31 +
32 + let hash: Fingerprint = hasher.finish();
33 + cache.borrow_mut().insert(key, hash);
34 + hash
35 + });
36 +
37 + hash.hash_stable(hcx, hasher);
38 + }
39 +}
40 +
41 +impl<'a, 'tcx, T> ToStableHashKey<StableHashingContext<'a>> for &'tcx ty::List<T>
42 +where
43 + T: HashStable<StableHashingContext<'a>>,
44 +{
45 + type KeyType = Fingerprint;
46 +
47 + #[inline]
48 + fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> Fingerprint {
49 + let mut hasher = StableHasher::new();
50 + let mut hcx: StableHashingContext<'a> = hcx.clone();
51 + self.hash_stable(&mut hcx, &mut hasher);
52 + hasher.finish()
53 + }
54 +}
55 +
56 +impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::subst::GenericArg<'tcx> {
57 + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
58 + self.unpack().hash_stable(hcx, hasher);
59 + }
60 +}
61 +
62 +impl<'a> HashStable<StableHashingContext<'a>>
63 +for ty::RegionKind {
64 + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
46 65 mem::discriminant(self).hash_stable(hcx, hasher);
47 66 match *self {
48 67 ty::ReErased |
49 68 ty::ReStatic |
50 69 ty::ReEmpty => {
51 70 // No variant fields to hash for these ...
52 71 }
53 72 ty::ReLateBound(db, ty::BrAnon(i)) => {
54 - db.depth.hash_stable(hcx, hasher);
73 + db.hash_stable(hcx, hasher);
55 74 i.hash_stable(hcx, hasher);
75 + }
76 + ty::ReLateBound(db, ty::BrNamed(def_id, name)) => {
77 + db.hash_stable(hcx, hasher);
78 + def_id.hash_stable(hcx, hasher);
79 + name.hash_stable(hcx, hasher);
80 + }
81 + ty::ReLateBound(db, ty::BrEnv) => {
82 + db.hash_stable(hcx, hasher);
56 83 }
57 84 ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index, name }) => {
58 85 def_id.hash_stable(hcx, hasher);
59 86 index.hash_stable(hcx, hasher);
60 87 name.hash_stable(hcx, hasher);
61 88 }
62 - ty::ReScope(code_extent) => {
63 - code_extent.hash_stable(hcx, hasher);
89 + ty::ReScope(scope) => {
90 + scope.hash_stable(hcx, hasher);
64 91 }
65 92 ty::ReFree(ref free_region) => {
66 93 free_region.hash_stable(hcx, hasher);
67 94 }
68 - ty::ReLateBound(..) |
69 - ty::ReVar(..) |
70 - ty::ReSkolemized(..) => {
71 - bug!("TypeIdHasher: unexpected region {:?}", *self)
95 + ty::ReClosureBound(vid) => {
96 + vid.hash_stable(hcx, hasher);
72 97 }
73 - }
74 - }
75 -}
76 -
77 -impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::adjustment::AutoBorrow<'tcx> {
78 - fn hash_stable<W: StableHasherResult>(&self,
79 - hcx: &mut StableHashingContext<'a, 'tcx>,
80 - hasher: &mut StableHasher<W>) {
81 - mem::discriminant(self).hash_stable(hcx, hasher);
82 - match *self {
83 - ty::adjustment::AutoBorrow::Ref(ref region, mutability) => {
84 - region.hash_stable(hcx, hasher);
85 - mutability.hash_stable(hcx, hasher);
86 - }
87 - ty::adjustment::AutoBorrow::RawPtr(mutability) => {
88 - mutability.hash_stable(hcx, hasher);
98 + ty::ReVar(..) |
99 + ty::RePlaceholder(..) => {
100 + bug!("StableHasher: unexpected region {:?}", *self)
89 101 }
90 102 }
91 103 }
92 104 }
93 105
94 -impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::adjustment::Adjust<'tcx> {
95 - fn hash_stable<W: StableHasherResult>(&self,
96 - hcx: &mut StableHashingContext<'a, 'tcx>,
97 - hasher: &mut StableHasher<W>) {
98 - mem::discriminant(self).hash_stable(hcx, hasher);
99 - match *self {
100 - ty::adjustment::Adjust::NeverToAny |
101 - ty::adjustment::Adjust::ReifyFnPointer |
102 - ty::adjustment::Adjust::UnsafeFnPointer |
103 - ty::adjustment::Adjust::ClosureFnPointer |
104 - ty::adjustment::Adjust::MutToConstPointer => {}
105 - ty::adjustment::Adjust::DerefRef { autoderefs, ref autoref, unsize } => {
106 - autoderefs.hash_stable(hcx, hasher);
107 - autoref.hash_stable(hcx, hasher);
108 - unsize.hash_stable(hcx, hasher);
109 - }
110 - }
106 +impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionVid {
107 + #[inline]
108 + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
109 + self.index().hash_stable(hcx, hasher);
110 + }
111 +}
112 +
113 +impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::ConstVid<'tcx> {
114 + #[inline]
115 + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
116 + self.index.hash_stable(hcx, hasher);
117 + }
118 +}
119 +
120 +impl<'tcx> HashStable<StableHashingContext<'tcx>> for ty::BoundVar {
121 + #[inline]
122 + fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) {
123 + self.index().hash_stable(hcx, hasher);
124 + }
125 +}
126 +
127 +impl<'a, T> HashStable<StableHashingContext<'a>> for ty::Binder<T>
128 +where
129 + T: HashStable<StableHashingContext<'a>>,
130 +{
131 + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
132 + self.skip_binder().hash_stable(hcx, hasher);
111 133 }
112 134 }
113 135
114 -impl_stable_hash_for!(struct ty::adjustment::Adjustment<'tcx> { kind, target });
115 -impl_stable_hash_for!(struct ty::MethodCall { expr_id, autoderef });
116 -impl_stable_hash_for!(struct ty::MethodCallee<'tcx> { def_id, ty, substs });
117 -impl_stable_hash_for!(struct ty::UpvarId { var_id, closure_expr_id });
118 -impl_stable_hash_for!(struct ty::UpvarBorrow<'tcx> { kind, region });
119 -
120 -impl_stable_hash_for!(enum ty::BorrowKind {
121 - ImmBorrow,
122 - UniqueImmBorrow,
123 - MutBorrow
124 -});
125 -
126 -impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::UpvarCapture<'tcx> {
127 - fn hash_stable<W: StableHasherResult>(&self,
128 - hcx: &mut StableHashingContext<'a, 'tcx>,
129 - hasher: &mut StableHasher<W>) {
130 - mem::discriminant(self).hash_stable(hcx, hasher);
131 - match *self {
132 - ty::UpvarCapture::ByValue => {}
133 - ty::UpvarCapture::ByRef(ref up_var_borrow) => {
134 - up_var_borrow.hash_stable(hcx, hasher);
135 - }
136 - }
136 +// AllocIds get resolved to whatever they point to (to be stable)
137 +impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
138 + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
139 + ty::tls::with_opt(|tcx| {
140 + trace!("hashing {:?}", *self);
141 + let tcx = tcx.expect("can't hash AllocIds during hir lowering");
142 + let alloc_kind = tcx.alloc_map.lock().get(*self);
143 + alloc_kind.hash_stable(hcx, hasher);
144 + });
137 145 }
138 146 }
139 147
140 -impl_stable_hash_for!(struct ty::FnSig<'tcx> {
141 - inputs_and_output,
142 - variadic,
143 - unsafety,
144 - abi
145 -});
146 -
147 -impl<'a, 'tcx, T> HashStable<StableHashingContext<'a, 'tcx>> for ty::Binder<T>
148 - where T: HashStable<StableHashingContext<'a, 'tcx>> + ty::fold::TypeFoldable<'tcx>
148 +// `Relocations` with default type parameters is a sorted map.
149 +impl<'a, Tag> HashStable<StableHashingContext<'a>>
150 +for mir::interpret::Relocations<Tag>
151 +where
152 + Tag: HashStable<StableHashingContext<'a>>,
149 153 {
150 - fn hash_stable<W: StableHasherResult>(&self,
151 - hcx: &mut StableHashingContext<'a, 'tcx>,
152 - hasher: &mut StableHasher<W>) {
153 - hcx.tcx().anonymize_late_bound_regions(self).0.hash_stable(hcx, hasher);
154 - }
155 -}
156 -
157 -impl_stable_hash_for!(enum ty::ClosureKind { Fn, FnMut, FnOnce });
158 -
159 -impl_stable_hash_for!(enum ty::Visibility {
160 - Public,
161 - Restricted(def_id),
162 - Invisible
163 -});
164 -
165 -impl_stable_hash_for!(struct ty::TraitRef<'tcx> { def_id, substs });
166 -impl_stable_hash_for!(struct ty::TraitPredicate<'tcx> { trait_ref });
167 -impl_stable_hash_for!(tuple_struct ty::EquatePredicate<'tcx> { t1, t2 });
168 -impl_stable_hash_for!(struct ty::SubtypePredicate<'tcx> { a_is_expected, a, b });
169 -
170 -impl<'a, 'tcx, A, B> HashStable<StableHashingContext<'a, 'tcx>> for ty::OutlivesPredicate<A, B>
171 - where A: HashStable<StableHashingContext<'a, 'tcx>>,
172 - B: HashStable<StableHashingContext<'a, 'tcx>>,
173 -{
174 - fn hash_stable<W: StableHasherResult>(&self,
175 - hcx: &mut StableHashingContext<'a, 'tcx>,
176 - hasher: &mut StableHasher<W>) {
177 - let ty::OutlivesPredicate(ref a, ref b) = *self;
178 - a.hash_stable(hcx, hasher);
179 - b.hash_stable(hcx, hasher);
180 - }
181 -}
182 -
183 -impl_stable_hash_for!(struct ty::ProjectionPredicate<'tcx> { projection_ty, ty });
184 -impl_stable_hash_for!(struct ty::ProjectionTy<'tcx> { trait_ref, item_name });
185 -
186 -
187 -impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::Predicate<'tcx> {
188 - fn hash_stable<W: StableHasherResult>(&self,
189 - hcx: &mut StableHashingContext<'a, 'tcx>,
190 - hasher: &mut StableHasher<W>) {
191 - mem::discriminant(self).hash_stable(hcx, hasher);
192 - match *self {
193 - ty::Predicate::Trait(ref pred) => {
194 - pred.hash_stable(hcx, hasher);
195 - }
196 - ty::Predicate::Equate(ref pred) => {
197 - pred.hash_stable(hcx, hasher);
198 - }
199 - ty::Predicate::Subtype(ref pred) => {
200 - pred.hash_stable(hcx, hasher);
201 - }
202 - ty::Predicate::RegionOutlives(ref pred) => {
203 - pred.hash_stable(hcx, hasher);
204 - }
205 - ty::Predicate::TypeOutlives(ref pred) => {
206 - pred.hash_stable(hcx, hasher);
207 - }
208 - ty::Predicate::Projection(ref pred) => {
209 - pred.hash_stable(hcx, hasher);
210 - }
211 - ty::Predicate::WellFormed(ty) => {
212 - ty.hash_stable(hcx, hasher);
213 - }
214 - ty::Predicate::ObjectSafe(def_id) => {
215 - def_id.hash_stable(hcx, hasher);
216 - }
217 - ty::Predicate::ClosureKind(def_id, closure_kind) => {
218 - def_id.hash_stable(hcx, hasher);
219 - closure_kind.hash_stable(hcx, hasher);
220 - }
154 + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
155 + self.len().hash_stable(hcx, hasher);
156 + for reloc in self.iter() {
157 + reloc.hash_stable(hcx, hasher);
221 158 }
222 159 }
223 160 }
224 161
225 -impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::AdtFlags {
226 - fn hash_stable<W: StableHasherResult>(&self,
227 - _: &mut StableHashingContext<'a, 'tcx>,
228 - hasher: &mut StableHasher<W>) {
229 - std_hash::Hash::hash(self, hasher);
162 +impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
163 + type KeyType = region::Scope;
164 +
165 + #[inline]
166 + fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> region::Scope {
167 + *self
168 + }
169 +}
170 +
171 +impl<'a> HashStable<StableHashingContext<'a>> for ty::TyVid {
172 + fn hash_stable(&self, _hcx: &mut StableHashingContext<'a>, _hasher: &mut StableHasher) {
173 + // `TyVid` values are confined to an inference context and hence
174 + // should not be hashed.
175 + bug!("ty::TyKind::hash_stable() - can't hash a TyVid {:?}.", *self)
176 + }
177 +}
178 +
179 +impl<'a> HashStable<StableHashingContext<'a>> for ty::IntVid {
180 + fn hash_stable(&self, _hcx: &mut StableHashingContext<'a>, _hasher: &mut StableHasher) {
181 + // `IntVid` values are confined to an inference context and hence
182 + // should not be hashed.
183 + bug!("ty::TyKind::hash_stable() - can't hash an IntVid {:?}.", *self)
184 + }
185 +}
186 +
187 +impl<'a> HashStable<StableHashingContext<'a>> for ty::FloatVid {
188 + fn hash_stable(&self, _hcx: &mut StableHashingContext<'a>, _hasher: &mut StableHasher) {
189 + // `FloatVid` values are confined to an inference context and hence
190 + // should not be hashed.
191 + bug!("ty::TyKind::hash_stable() - can't hash a FloatVid {:?}.", *self)
230 192 }
231 193 }
232 194
233 -impl_stable_hash_for!(struct ty::VariantDef {
234 - did,
235 - name,
236 - discr,
237 - fields,
238 - ctor_kind
239 -});
240 -
241 -impl_stable_hash_for!(enum ty::VariantDiscr {
242 - Explicit(def_id),
243 - Relative(distance)
244 -});
245 -
246 -impl_stable_hash_for!(struct ty::FieldDef {
247 - did,
248 - name,
249 - vis
250 -});
251 -
252 -impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>>
253 -for ::middle::const_val::ConstVal<'tcx> {
254 - fn hash_stable<W: StableHasherResult>(&self,
255 - hcx: &mut StableHashingContext<'a, 'tcx>,
256 - hasher: &mut StableHasher<W>) {
257 - use middle::const_val::ConstVal;
258 -
259 - mem::discriminant(self).hash_stable(hcx, hasher);
260 -
261 - match *self {
262 - ConstVal::Float(ref value) => {
263 - value.hash_stable(hcx, hasher);
264 - }
265 - ConstVal::Integral(ref value) => {
266 - value.hash_stable(hcx, hasher);
267 - }
268 - ConstVal::Str(ref value) => {
269 - value.hash_stable(hcx, hasher);
270 - }
271 - ConstVal::ByteStr(ref value) => {
272 - value.hash_stable(hcx, hasher);
273 - }
274 - ConstVal::Bool(value) => {
275 - value.hash_stable(hcx, hasher);
276 - }
277 - ConstVal::Char(value) => {
278 - value.hash_stable(hcx, hasher);
279 - }
280 - ConstVal::Variant(def_id) => {
281 - def_id.hash_stable(hcx, hasher);
282 - }
283 - ConstVal::Function(def_id, substs) => {
284 - def_id.hash_stable(hcx, hasher);
285 - substs.hash_stable(hcx, hasher);
286 - }
287 - ConstVal::Struct(ref name_value_map) => {
288 - let mut values: Vec<(InternedString, &ConstVal)> =
289 - name_value_map.iter()
290 - .map(|(name, val)| (name.as_str(), val))
291 - .collect();
292 -
293 - values.sort_unstable_by_key(|&(ref name, _)| name.clone());
294 - values.hash_stable(hcx, hasher);
295 - }
296 - ConstVal::Tuple(ref value) => {
297 - value.hash_stable(hcx, hasher);
298 - }
299 - ConstVal::Array(ref value) => {
300 - value.hash_stable(hcx, hasher);
301 - }
302 - ConstVal::Repeat(ref value, times) => {
303 - value.hash_stable(hcx, hasher);
304 - times.hash_stable(hcx, hasher);
305 - }
306 - }
195 +impl<'a, T> HashStable<StableHashingContext<'a>> for ty::steal::Steal<T>
196 +where
197 + T: HashStable<StableHashingContext<'a>>,
198 +{
199 + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
200 + self.borrow().hash_stable(hcx, hasher);
307 201 }
308 202 }
309 203
310 -impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs });
311 -
312 -impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
313 - parent,
314 - predicates
315 -});
316 -
317 -impl_stable_hash_for!(enum ty::Variance {
318 - Covariant,
319 - Invariant,
320 - Contravariant,
321 - Bivariant
322 -});
204 +impl<'a> HashStable<StableHashingContext<'a>>
205 +for crate::middle::privacy::AccessLevels {
206 + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
207 + hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
208 + let crate::middle::privacy::AccessLevels {
209 + ref map
210 + } = *self;
323 211
324 -impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized {
325 - Struct(index)
326 -});
327 -
328 -impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::Generics {
329 - fn hash_stable<W: StableHasherResult>(&self,
330 - hcx: &mut StableHashingContext<'a, 'tcx>,
331 - hasher: &mut StableHasher<W>) {
332 - let ty::Generics {
333 - parent,
334 - parent_regions,
335 - parent_types,
336 - ref regions,
337 - ref types,
338 -
339 - // Reverse map to each `TypeParameterDef`'s `index` field, from
340 - // `def_id.index` (`def_id.krate` is the same as the item's).
341 - type_param_to_index: _, // Don't hash this
342 - has_self,
343 - } = *self;
344 -
345 - parent.hash_stable(hcx, hasher);
346 - parent_regions.hash_stable(hcx, hasher);
347 - parent_types.hash_stable(hcx, hasher);
348 - regions.hash_stable(hcx, hasher);
349 - types.hash_stable(hcx, hasher);
350 - has_self.hash_stable(hcx, hasher);
351 - }
352 -}
353 -
354 -impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::RegionParameterDef {
355 - fn hash_stable<W: StableHasherResult>(&self,
356 - hcx: &mut StableHashingContext<'a, 'tcx>,
357 - hasher: &mut StableHasher<W>) {
358 - let ty::RegionParameterDef {
359 - name,
360 - def_id,
361 - index,
362 - issue_32330: _,
363 - pure_wrt_drop
364 - } = *self;
365 -
366 - name.hash_stable(hcx, hasher);
367 - def_id.hash_stable(hcx, hasher);
368 - index.hash_stable(hcx, hasher);
369 - pure_wrt_drop.hash_stable(hcx, hasher);
370 - }
371 -}
372 -
373 -impl_stable_hash_for!(struct ty::TypeParameterDef {
374 - name,
375 - def_id,
376 - index,
377 - has_default,
378 - object_lifetime_default,
379 - pure_wrt_drop
380 -});
381 -
382 -
383 -impl<'a, 'tcx, T> HashStable<StableHashingContext<'a, 'tcx>>
384 -for ::middle::resolve_lifetime::Set1<T>
385 - where T: HashStable<StableHashingContext<'a, 'tcx>>
386 -{
387 - fn hash_stable<W: StableHasherResult>(&self,
388 - hcx: &mut StableHashingContext<'a, 'tcx>,
389 - hasher: &mut StableHasher<W>) {
390 - use middle::resolve_lifetime::Set1;
391 -
392 - mem::discriminant(self).hash_stable(hcx, hasher);
393 - match *self {
394 - Set1::Empty |
395 - Set1::Many => {
396 - // Nothing to do.
397 - }
398 - Set1::One(ref value) => {
399 - value.hash_stable(hcx, hasher);
400 - }
401 - }
402 - }
403 -}
404 -
405 -impl_stable_hash_for!(enum ::middle::resolve_lifetime::Region {
406 - Static,
407 - EarlyBound(index, decl),
408 - LateBound(db_index, decl),
409 - LateBoundAnon(db_index, anon_index),
410 - Free(call_site_scope_data, decl)
411 -});
412 -
413 -impl_stable_hash_for!(struct ty::DebruijnIndex {
414 - depth
415 -});
416 -
417 -impl_stable_hash_for!(enum ty::cast::CastKind {
418 - CoercionCast,
419 - PtrPtrCast,
420 - PtrAddrCast,
421 - AddrPtrCast,
422 - NumericCast,
423 - EnumCast,
424 - PrimIntCast,
425 - U8CharCast,
426 - ArrayPtrCast,
427 - FnPtrPtrCast,
428 - FnPtrAddrCast
429 -});
430 -
431 -impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ::middle::region::CodeExtent
432 -{
433 - fn hash_stable<W: StableHasherResult>(&self,
434 - hcx: &mut StableHashingContext<'a, 'tcx>,
435 - hasher: &mut StableHasher<W>) {
436 - use middle::region::CodeExtent;
437 -
438 - mem::discriminant(self).hash_stable(hcx, hasher);
439 - match *self {
440 - CodeExtent::Misc(node_id) |
441 - CodeExtent::DestructionScope(node_id) => {
442 - node_id.hash_stable(hcx, hasher);
443 - }
444 - CodeExtent::CallSiteScope(body_id) |
445 - CodeExtent::ParameterScope(body_id) => {
446 - body_id.hash_stable(hcx, hasher);
447 - }
448 - CodeExtent::Remainder(block_remainder) => {
449 - block_remainder.hash_stable(hcx, hasher);
450 - }
451 - }
452 - }
453 -}
454 -
455 -impl_stable_hash_for!(struct ::middle::region::BlockRemainder {
456 - block,
457 - first_statement_index
458 -});
459 -
460 -impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
461 - custom_kind
462 -});
463 -
464 -impl_stable_hash_for!(struct ty::FreeRegion {
465 - scope,
466 - bound_region
467 -});
468 -
469 -impl_stable_hash_for!(enum ty::BoundRegion {
470 - BrAnon(index),
471 - BrNamed(def_id, name),
472 - BrFresh(index),
473 - BrEnv
474 -});
475 -
476 -impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::TypeVariants<'tcx>
477 -{
478 - fn hash_stable<W: StableHasherResult>(&self,
479 - hcx: &mut StableHashingContext<'a, 'tcx>,
480 - hasher: &mut StableHasher<W>) {
481 - use ty::TypeVariants::*;
482 -
483 - mem::discriminant(self).hash_stable(hcx, hasher);
484 - match *self {
485 - TyBool |
486 - TyChar |
487 - TyStr |
488 - TyNever => {
489 - // Nothing more to hash.
490 - }
491 - TyInt(int_ty) => {
492 - int_ty.hash_stable(hcx, hasher);
493 - }
494 - TyUint(uint_ty) => {
495 - uint_ty.hash_stable(hcx, hasher);
496 - }
497 - TyFloat(float_ty) => {
498 - float_ty.hash_stable(hcx, hasher);
499 - }
500 - TyAdt(adt_def, substs) => {
501 - adt_def.hash_stable(hcx, hasher);
502 - substs.hash_stable(hcx, hasher);
503 - }
504 - TyArray(inner_ty, len) => {
505 - inner_ty.hash_stable(hcx, hasher);
506 - len.hash_stable(hcx, hasher);
507 - }
508 - TySlice(inner_ty) => {
509 - inner_ty.hash_stable(hcx, hasher);
510 - }
511 - TyRawPtr(pointee_ty) => {
512 - pointee_ty.hash_stable(hcx, hasher);
513 - }
514 - TyRef(region, pointee_ty) => {
515 - region.hash_stable(hcx, hasher);
516 - pointee_ty.hash_stable(hcx, hasher);
517 - }
518 - TyFnDef(def_id, substs, ref sig) => {
519 - def_id.hash_stable(hcx, hasher);
520 - substs.hash_stable(hcx, hasher);
521 - sig.hash_stable(hcx, hasher);
522 - }
523 - TyFnPtr(ref sig) => {
524 - sig.hash_stable(hcx, hasher);
525 - }
526 - TyDynamic(ref existential_predicates, region) => {
527 - existential_predicates.hash_stable(hcx, hasher);
528 - region.hash_stable(hcx, hasher);
529 - }
530 - TyClosure(def_id, closure_substs) => {
531 - def_id.hash_stable(hcx, hasher);
532 - closure_substs.hash_stable(hcx, hasher);
533 - }
534 - TyTuple(inner_tys, from_diverging_type_var) => {
535 - inner_tys.hash_stable(hcx, hasher);
536 - from_diverging_type_var.hash_stable(hcx, hasher);
537 - }
538 - TyProjection(ref projection_ty) => {
539 - projection_ty.hash_stable(hcx, hasher);
540 - }
541 - TyAnon(def_id, substs) => {
542 - def_id.hash_stable(hcx, hasher);
543 - substs.hash_stable(hcx, hasher);
544 - }
545 - TyParam(param_ty) => {
546 - param_ty.hash_stable(hcx, hasher);
547 - }
548 -
549 - TyError |
550 - TyInfer(..) => {
551 - bug!("ty::TypeVariants::hash_stable() - Unexpected variant.")
552 - }
553 - }
554 - }
555 -}
556 -
557 -impl_stable_hash_for!(struct ty::ParamTy {
558 - idx,
559 - name
560 -});
561 -
562 -impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> {
563 - ty,
564 - mutbl
565 -});
566 -
567 -impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::ExistentialPredicate<'tcx>
568 -{
569 - fn hash_stable<W: StableHasherResult>(&self,
570 - hcx: &mut StableHashingContext<'a, 'tcx>,
571 - hasher: &mut StableHasher<W>) {
572 - mem::discriminant(self).hash_stable(hcx, hasher);
573 - match *self {
574 - ty::ExistentialPredicate::Trait(ref trait_ref) => {
575 - trait_ref.hash_stable(hcx, hasher);
576 - }
577 - ty::ExistentialPredicate::Projection(ref projection) => {
578 - projection.hash_stable(hcx, hasher);
579 - }
580 - ty::ExistentialPredicate::AutoTrait(def_id) => {
581 - def_id.hash_stable(hcx, hasher);
582 - }
583 - }
584 - }
585 -}
586 -
587 -impl_stable_hash_for!(struct ty::ExistentialTraitRef<'tcx> {
588 - def_id,
589 - substs
590 -});
591 -
592 -impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> {
593 - trait_ref,
594 - item_name,
595 - ty
596 -});
597 -
598 -
599 -impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::TypeckTables<'tcx> {
600 - fn hash_stable<W: StableHasherResult>(&self,
601 - hcx: &mut StableHashingContext<'a, 'tcx>,
602 - hasher: &mut StableHasher<W>) {
603 - let ty::TypeckTables {
604 - ref type_relative_path_defs,
605 - ref node_types,
606 - ref item_substs,
607 - ref adjustments,
608 - ref method_map,
609 - ref upvar_capture_map,
610 - ref closure_tys,
611 - ref closure_kinds,
612 - ref liberated_fn_sigs,
613 - ref fru_field_types,
614 -
615 - ref cast_kinds,
616 -
617 - // FIXME(#41184): This is still ignored at the moment.
618 - lints: _,
619 - ref used_trait_imports,
620 - tainted_by_errors,
621 - ref free_region_map,
622 - } = *self;
623 -
624 - hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
625 - ich::hash_stable_nodemap(hcx, hasher, type_relative_path_defs);
626 - ich::hash_stable_nodemap(hcx, hasher, node_types);
627 - ich::hash_stable_nodemap(hcx, hasher, item_substs);
628 - ich::hash_stable_nodemap(hcx, hasher, adjustments);
629 -
630 - ich::hash_stable_hashmap(hcx, hasher, method_map, |hcx, method_call| {
631 - let ty::MethodCall {
632 - expr_id,
633 - autoderef
634 - } = *method_call;
635 -
636 - let def_id = hcx.tcx().hir.local_def_id(expr_id);
637 - (hcx.def_path_hash(def_id), autoderef)
638 - });
639 -
640 - ich::hash_stable_hashmap(hcx, hasher, upvar_capture_map, |hcx, up_var_id| {
641 - let ty::UpvarId {
642 - var_id,
643 - closure_expr_id
644 - } = *up_var_id;
645 -
646 - let var_def_id = hcx.tcx().hir.local_def_id(var_id);
647 - let closure_def_id = hcx.tcx().hir.local_def_id(closure_expr_id);
648 - (hcx.def_path_hash(var_def_id), hcx.def_path_hash(closure_def_id))
649 - });
650 -
651 - ich::hash_stable_nodemap(hcx, hasher, closure_tys);
652 - ich::hash_stable_nodemap(hcx, hasher, closure_kinds);
653 - ich::hash_stable_nodemap(hcx, hasher, liberated_fn_sigs);
654 - ich::hash_stable_nodemap(hcx, hasher, fru_field_types);
655 - ich::hash_stable_nodemap(hcx, hasher, cast_kinds);
656 -
657 - ich::hash_stable_hashset(hcx, hasher, used_trait_imports, |hcx, def_id| {
658 - hcx.def_path_hash(*def_id)
659 - });
660 -
661 - tainted_by_errors.hash_stable(hcx, hasher);
662 - free_region_map.hash_stable(hcx, hasher);
663 - })
212 + map.hash_stable(hcx, hasher);
213 + });
664 214 }
665 215 }