@@ -335,8 +335,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
335335 expected : Ty < ' tcx > ,
336336 mut def_bm : BindingMode ,
337337 ) -> ( Ty < ' tcx > , BindingMode ) {
338- let mut expected = self . resolve_vars_with_obligations ( expected) ;
339-
338+ let mut expected = self . try_structurally_resolve_type ( pat. span , expected) ;
340339 // Peel off as many `&` or `&mut` from the scrutinee type as possible. For example,
341340 // for `match &&&mut Some(5)` the loop runs three times, aborting when it reaches
342341 // the `Some(5)` which is not of type Ref.
@@ -353,7 +352,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
353352 // Preserve the reference type. We'll need it later during THIR lowering.
354353 pat_adjustments. push ( expected) ;
355354
356- expected = inner_ty;
355+ expected = self . try_structurally_resolve_type ( pat . span , inner_ty) ;
357356 def_bm = ty:: BindByReference ( match def_bm {
358357 // If default binding mode is by value, make it `ref` or `ref mut`
359358 // (depending on whether we observe `&` or `&mut`).
@@ -627,6 +626,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
627626 local_ty
628627 }
629628
629+ /// When a variable is bound several times in a `PatKind::Or`, it'll resolve all of the
630+ /// subsequent bindings of the same name to the first usage. Verify that all of these
631+ /// bindings have the same type by comparing them all against the type of that first pat.
630632 fn check_binding_alt_eq_ty (
631633 & self ,
632634 ba : hir:: BindingAnnotation ,
@@ -638,7 +640,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
638640 let var_ty = self . local_ty ( span, var_id) ;
639641 if let Some ( mut err) = self . demand_eqtype_pat_diag ( span, var_ty, ty, ti) {
640642 let hir = self . tcx . hir ( ) ;
641- let var_ty = self . resolve_vars_with_obligations ( var_ty) ;
643+ let var_ty = self . resolve_vars_if_possible ( var_ty) ;
642644 let msg = format ! ( "first introduced with type `{var_ty}` here" ) ;
643645 err. span_label ( hir. span ( var_id) , msg) ;
644646 let in_match = hir. parent_iter ( var_id) . any ( |( _, n) | {
@@ -656,7 +658,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
656658 & mut err,
657659 span,
658660 var_ty,
659- self . resolve_vars_with_obligations ( ty) ,
661+ self . resolve_vars_if_possible ( ty) ,
660662 ba,
661663 ) ;
662664 err. emit ( ) ;
0 commit comments