@@ -379,13 +379,13 @@ impl_stable_hash_for!(struct mir::interpret::MemoryPointer {
379
379
} ) ;
380
380
381
381
enum AllocDiscriminant {
382
- Static ,
383
- Constant ,
382
+ Alloc ,
383
+ ExternStatic ,
384
384
Function ,
385
385
}
386
386
impl_stable_hash_for ! ( enum self :: AllocDiscriminant {
387
- Static ,
388
- Constant ,
387
+ Alloc ,
388
+ ExternStatic ,
389
389
Function
390
390
} ) ;
391
391
@@ -397,17 +397,23 @@ impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
397
397
) {
398
398
ty:: tls:: with_opt ( |tcx| {
399
399
let tcx = tcx. expect ( "can't hash AllocIds during hir lowering" ) ;
400
- if let Some ( def_id) = tcx. interpret_interner . get_corresponding_static_def_id ( * self ) {
401
- AllocDiscriminant :: Static . hash_stable ( hcx, hasher) ;
402
- // statics are unique via their DefId
403
- def_id. hash_stable ( hcx, hasher) ;
404
- } else if let Some ( alloc) = tcx. interpret_interner . get_alloc ( * self ) {
405
- // not a static, can't be recursive, hash the allocation
406
- AllocDiscriminant :: Constant . hash_stable ( hcx, hasher) ;
407
- alloc. hash_stable ( hcx, hasher) ;
400
+ if let Some ( alloc) = tcx. interpret_interner . get_alloc ( * self ) {
401
+ AllocDiscriminant :: Alloc . hash_stable ( hcx, hasher) ;
402
+ if !hcx. alloc_id_recursion_tracker . insert ( * self ) {
403
+ tcx
404
+ . interpret_interner
405
+ . get_corresponding_static_def_id ( * self )
406
+ . hash_stable ( hcx, hasher) ;
407
+ alloc. hash_stable ( hcx, hasher) ;
408
+ assert ! ( hcx. alloc_id_recursion_tracker. remove( self ) ) ;
409
+ }
408
410
} else if let Some ( inst) = tcx. interpret_interner . get_fn ( * self ) {
409
411
AllocDiscriminant :: Function . hash_stable ( hcx, hasher) ;
410
412
inst. hash_stable ( hcx, hasher) ;
413
+ } else if let Some ( def_id) = tcx. interpret_interner
414
+ . get_corresponding_static_def_id ( * self ) {
415
+ AllocDiscriminant :: ExternStatic . hash_stable ( hcx, hasher) ;
416
+ def_id. hash_stable ( hcx, hasher) ;
411
417
} else {
412
418
bug ! ( "no allocation for {}" , self ) ;
413
419
}
0 commit comments