@@ -3751,36 +3751,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3751
3751
3752
3752
if let Some ( ref init) = local. init {
3753
3753
let init_ty = self . check_decl_initializer ( local, & init) ;
3754
- if init_ty. references_error ( ) {
3755
- // Override the types everywhere with `types.err` to avoid knock down errors.
3756
- self . write_ty ( local. hir_id , init_ty) ;
3757
- self . write_ty ( local. pat . hir_id , init_ty) ;
3758
- self . locals . borrow_mut ( ) . insert ( local. hir_id , LocalTy {
3759
- decl_ty : t,
3760
- revealed_ty : init_ty,
3761
- } ) ;
3762
- self . locals . borrow_mut ( ) . insert ( local. pat . hir_id , LocalTy {
3763
- decl_ty : t,
3764
- revealed_ty : init_ty,
3765
- } ) ;
3766
- }
3754
+ self . overwrite_local_ty_if_err ( local, t, init_ty) ;
3767
3755
}
3768
3756
3769
3757
self . check_pat_top ( & local. pat , t, None ) ;
3770
3758
let pat_ty = self . node_ty ( local. pat . hir_id ) ;
3771
- debug ! ( "check_decl_local pat_ty {:?}" , pat_ty) ;
3772
- if pat_ty. references_error ( ) {
3759
+ self . overwrite_local_ty_if_err ( local, t, pat_ty) ;
3760
+ }
3761
+
3762
+ fn overwrite_local_ty_if_err ( & self , local : & ' tcx hir:: Local , decl_ty : Ty < ' tcx > , ty : Ty < ' tcx > ) {
3763
+ if ty. references_error ( ) {
3773
3764
// Override the types everywhere with `types.err` to avoid knock down errors.
3774
- self . write_ty ( local. hir_id , pat_ty) ;
3775
- self . write_ty ( local. pat . hir_id , pat_ty) ;
3776
- self . locals . borrow_mut ( ) . insert ( local. hir_id , LocalTy {
3777
- decl_ty : t,
3778
- revealed_ty : pat_ty,
3779
- } ) ;
3780
- self . locals . borrow_mut ( ) . insert ( local. pat . hir_id , LocalTy {
3781
- decl_ty : t,
3782
- revealed_ty : pat_ty,
3783
- } ) ;
3765
+ self . write_ty ( local. hir_id , ty) ;
3766
+ self . write_ty ( local. pat . hir_id , ty) ;
3767
+ let local_ty = LocalTy {
3768
+ decl_ty,
3769
+ revealed_ty : ty,
3770
+ } ;
3771
+ self . locals . borrow_mut ( ) . insert ( local. hir_id , local_ty) ;
3772
+ self . locals . borrow_mut ( ) . insert ( local. pat . hir_id , local_ty) ;
3784
3773
}
3785
3774
}
3786
3775
0 commit comments