@@ -451,6 +451,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
451451 CaptureClause :: CaptureByRef => 1 ,
452452 }
453453 . hash ( & mut self . s ) ;
454+ // closures inherit TypeckTables
454455 self . hash_expr ( & self . cx . tcx . hir ( ) . body ( eid) . value ) ;
455456 } ,
456457 ExprKind :: Field ( ref e, ref f) => {
@@ -490,10 +491,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
490491 } ,
491492 ExprKind :: Repeat ( ref e, ref l_id) => {
492493 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 ) ;
497495 } ,
498496 ExprKind :: Ret ( ref e) => {
499497 if let Some ( ref e) = * e {
@@ -609,7 +607,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
609607 } ,
610608 TyKind :: Array ( ty, anon_const) => {
611609 self . hash_ty ( ty) ;
612- self . hash_expr ( & self . cx . tcx . hir ( ) . body ( anon_const. body ) . value ) ;
610+ self . hash_body ( anon_const. body ) ;
613611 } ,
614612 TyKind :: Ptr ( mut_ty) => {
615613 self . hash_ty ( & mut_ty. ty ) ;
@@ -660,19 +658,25 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
660658 match arg {
661659 GenericArg :: Lifetime ( ref l) => self . hash_lifetime ( l) ,
662660 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 ) ,
666662 }
667663 }
668664 } ,
669665 TyKind :: TraitObject ( _, lifetime) => {
670666 self . hash_lifetime ( lifetime) ;
671667 } ,
672668 TyKind :: Typeof ( anon_const) => {
673- self . hash_expr ( & self . cx . tcx . hir ( ) . body ( anon_const. body ) . value ) ;
669+ self . hash_body ( anon_const. body ) ;
674670 } ,
675671 TyKind :: Err | TyKind :: Infer | TyKind :: Never => { } ,
676672 }
677673 }
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+ }
678682}
0 commit comments