@@ -335,8 +335,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
335
335
expected : Ty < ' tcx > ,
336
336
mut def_bm : BindingMode ,
337
337
) -> ( 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) ;
340
339
// Peel off as many `&` or `&mut` from the scrutinee type as possible. For example,
341
340
// for `match &&&mut Some(5)` the loop runs three times, aborting when it reaches
342
341
// the `Some(5)` which is not of type Ref.
@@ -353,7 +352,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
353
352
// Preserve the reference type. We'll need it later during THIR lowering.
354
353
pat_adjustments. push ( expected) ;
355
354
356
- expected = inner_ty;
355
+ expected = self . try_structurally_resolve_type ( pat . span , inner_ty) ;
357
356
def_bm = ty:: BindByReference ( match def_bm {
358
357
// If default binding mode is by value, make it `ref` or `ref mut`
359
358
// (depending on whether we observe `&` or `&mut`).
@@ -627,6 +626,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
627
626
local_ty
628
627
}
629
628
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.
630
632
fn check_binding_alt_eq_ty (
631
633
& self ,
632
634
ba : hir:: BindingAnnotation ,
@@ -638,7 +640,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
638
640
let var_ty = self . local_ty ( span, var_id) ;
639
641
if let Some ( mut err) = self . demand_eqtype_pat_diag ( span, var_ty, ty, ti) {
640
642
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) ;
642
644
let msg = format ! ( "first introduced with type `{var_ty}` here" ) ;
643
645
err. span_label ( hir. span ( var_id) , msg) ;
644
646
let in_match = hir. parent_iter ( var_id) . any ( |( _, n) | {
@@ -656,7 +658,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
656
658
& mut err,
657
659
span,
658
660
var_ty,
659
- self . resolve_vars_with_obligations ( ty) ,
661
+ self . resolve_vars_if_possible ( ty) ,
660
662
ba,
661
663
) ;
662
664
err. emit ( ) ;
0 commit comments