@@ -451,6 +451,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
451
451
CaptureClause :: CaptureByRef => 1 ,
452
452
}
453
453
. hash ( & mut self . s ) ;
454
+ // closures inherit TypeckTables
454
455
self . hash_expr ( & self . cx . tcx . hir ( ) . body ( eid) . value ) ;
455
456
} ,
456
457
ExprKind :: Field ( ref e, ref f) => {
@@ -490,10 +491,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
490
491
} ,
491
492
ExprKind :: Repeat ( ref e, ref l_id) => {
492
493
self . hash_expr ( e) ;
493
- let full_table = self . tables ;
494
- self . tables = self . cx . tcx . body_tables ( l_id. body ) ;
495
- self . hash_expr ( & self . cx . tcx . hir ( ) . body ( l_id. body ) . value ) ;
496
- self . tables = full_table;
494
+ self . hash_body ( l_id. body ) ;
497
495
} ,
498
496
ExprKind :: Ret ( ref e) => {
499
497
if let Some ( ref e) = * e {
@@ -609,7 +607,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
609
607
} ,
610
608
TyKind :: Array ( ty, anon_const) => {
611
609
self . hash_ty ( ty) ;
612
- self . hash_expr ( & self . cx . tcx . hir ( ) . body ( anon_const. body ) . value ) ;
610
+ self . hash_body ( anon_const. body ) ;
613
611
} ,
614
612
TyKind :: Ptr ( mut_ty) => {
615
613
self . hash_ty ( & mut_ty. ty ) ;
@@ -660,19 +658,25 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
660
658
match arg {
661
659
GenericArg :: Lifetime ( ref l) => self . hash_lifetime ( l) ,
662
660
GenericArg :: Type ( ref ty) => self . hash_ty ( & ty) ,
663
- GenericArg :: Const ( ref ca) => {
664
- self . hash_expr ( & self . cx . tcx . hir ( ) . body ( ca. value . body ) . value ) ;
665
- } ,
661
+ GenericArg :: Const ( ref ca) => self . hash_body ( ca. value . body ) ,
666
662
}
667
663
}
668
664
} ,
669
665
TyKind :: TraitObject ( _, lifetime) => {
670
666
self . hash_lifetime ( lifetime) ;
671
667
} ,
672
668
TyKind :: Typeof ( anon_const) => {
673
- self . hash_expr ( & self . cx . tcx . hir ( ) . body ( anon_const. body ) . value ) ;
669
+ self . hash_body ( anon_const. body ) ;
674
670
} ,
675
671
TyKind :: Err | TyKind :: Infer | TyKind :: Never => { } ,
676
672
}
677
673
}
674
+
675
+ pub fn hash_body ( & mut self , body_id : BodyId ) {
676
+ // swap out TypeckTables when hashing a body
677
+ let old_tables = self . tables ;
678
+ self . tables = self . cx . tcx . body_tables ( body_id) ;
679
+ self . hash_expr ( & self . cx . tcx . hir ( ) . body ( body_id) . value ) ;
680
+ self . tables = old_tables;
681
+ }
678
682
}
0 commit comments