@@ -60,29 +60,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
60
60
PatKind :: Path ( qpath) => Some ( self . resolve_ty_and_res_ufcs ( qpath, pat. hir_id , pat. span ) ) ,
61
61
_ => None ,
62
62
} ;
63
-
64
- let is_non_ref_pat = self . is_non_ref_pat ( pat, path_resolution. map ( |( res, ..) | res) ) ;
65
- let ( expected, def_bm) = if is_non_ref_pat {
66
- debug ! ( "pattern is non reference pattern" ) ;
67
- self . peel_off_references ( pat, expected, def_bm)
68
- } else {
69
- // When you encounter a `&pat` pattern, reset to "by
70
- // value". This is so that `x` and `y` here are by value,
71
- // as they appear to be:
72
- //
73
- // ```
74
- // match &(&22, &44) {
75
- // (&x, &y) => ...
76
- // }
77
- // ```
78
- //
79
- // See issue #46688.
80
- let def_bm = match pat. node {
81
- PatKind :: Ref ( ..) => ty:: BindByValue ( hir:: MutImmutable ) ,
82
- _ => def_bm,
83
- } ;
84
- ( expected, def_bm)
85
- } ;
63
+ let is_nrp = self . is_non_ref_pat ( pat, path_resolution. map ( |( res, ..) | res) ) ;
64
+ let ( expected, def_bm) = self . calc_default_binding_mode ( pat, expected, def_bm, is_nrp) ;
86
65
87
66
let ty = match pat. node {
88
67
PatKind :: Wild => {
@@ -495,6 +474,38 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
495
474
// subtyping.
496
475
}
497
476
477
+ /// Compute the new expected type and default binding mode from the old ones
478
+ /// as well as the pattern form we are currently checking.
479
+ fn calc_default_binding_mode (
480
+ & self ,
481
+ pat : & ' tcx hir:: Pat ,
482
+ expected : Ty < ' tcx > ,
483
+ def_bm : ty:: BindingMode ,
484
+ is_non_ref_pat : bool ,
485
+ ) -> ( Ty < ' tcx > , ty:: BindingMode ) {
486
+ if is_non_ref_pat {
487
+ debug ! ( "pattern is non reference pattern" ) ;
488
+ self . peel_off_references ( pat, expected, def_bm)
489
+ } else {
490
+ // When you encounter a `&pat` pattern, reset to "by
491
+ // value". This is so that `x` and `y` here are by value,
492
+ // as they appear to be:
493
+ //
494
+ // ```
495
+ // match &(&22, &44) {
496
+ // (&x, &y) => ...
497
+ // }
498
+ // ```
499
+ //
500
+ // See issue #46688.
501
+ let def_bm = match pat. node {
502
+ PatKind :: Ref ( ..) => ty:: BindByValue ( hir:: MutImmutable ) ,
503
+ _ => def_bm,
504
+ } ;
505
+ ( expected, def_bm)
506
+ }
507
+ }
508
+
498
509
/// Is the pattern a "non reference pattern"?
499
510
/// When the pattern is a path pattern, `opt_path_res` must be `Some(res)`.
500
511
fn is_non_ref_pat ( & self , pat : & ' tcx hir:: Pat , opt_path_res : Option < Res > ) -> bool {
0 commit comments