@@ -56,34 +56,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
56
56
57
57
debug ! ( "check_pat_walk(pat={:?},expected={:?},def_bm={:?})" , pat, expected, def_bm) ;
58
58
59
- let mut path_resolution = None ;
60
- let is_non_ref_pat = match pat. node {
61
- PatKind :: Struct ( ..) |
62
- PatKind :: TupleStruct ( ..) |
63
- PatKind :: Or ( _) |
64
- PatKind :: Tuple ( ..) |
65
- PatKind :: Box ( _) |
66
- PatKind :: Range ( ..) |
67
- PatKind :: Slice ( ..) => true ,
68
- PatKind :: Lit ( ref lt) => {
69
- let ty = self . check_expr ( lt) ;
70
- match ty. sty {
71
- ty:: Ref ( ..) => false ,
72
- _ => true ,
73
- }
74
- }
75
- PatKind :: Path ( ref qpath) => {
76
- let resolution = self . resolve_ty_and_res_ufcs ( qpath, pat. hir_id , pat. span ) ;
77
- path_resolution = Some ( resolution) ;
78
- match resolution. 0 {
79
- Res :: Def ( DefKind :: Const , _) | Res :: Def ( DefKind :: AssocConst , _) => false ,
80
- _ => true ,
81
- }
82
- }
83
- PatKind :: Wild |
84
- PatKind :: Binding ( ..) |
85
- PatKind :: Ref ( ..) => false ,
59
+ let path_resolution = match & pat. node {
60
+ PatKind :: Path ( qpath) => Some ( self . resolve_ty_and_res_ufcs ( qpath, pat. hir_id , pat. span ) ) ,
61
+ _ => None ,
86
62
} ;
63
+
64
+ let is_non_ref_pat = self . is_non_ref_pat ( pat, path_resolution. map ( |( res, ..) | res) ) ;
87
65
if is_non_ref_pat {
88
66
debug ! ( "pattern is non reference pattern" ) ;
89
67
let mut exp_ty = self . resolve_type_vars_with_obligations ( & expected) ;
@@ -560,6 +538,36 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
560
538
// subtyping.
561
539
}
562
540
541
+ /// Is the pattern a "non reference pattern"?
542
+ /// When the pattern is a path pattern, `opt_path_res` must be `Some(res)`.
543
+ fn is_non_ref_pat ( & self , pat : & ' tcx hir:: Pat , opt_path_res : Option < Res > ) -> bool {
544
+ match pat. node {
545
+ PatKind :: Struct ( ..) |
546
+ PatKind :: TupleStruct ( ..) |
547
+ PatKind :: Or ( _) |
548
+ PatKind :: Tuple ( ..) |
549
+ PatKind :: Box ( _) |
550
+ PatKind :: Range ( ..) |
551
+ PatKind :: Slice ( ..) => true ,
552
+ PatKind :: Lit ( ref lt) => {
553
+ let ty = self . check_expr ( lt) ;
554
+ match ty. sty {
555
+ ty:: Ref ( ..) => false ,
556
+ _ => true ,
557
+ }
558
+ }
559
+ PatKind :: Path ( _) => {
560
+ match opt_path_res. unwrap ( ) {
561
+ Res :: Def ( DefKind :: Const , _) | Res :: Def ( DefKind :: AssocConst , _) => false ,
562
+ _ => true ,
563
+ }
564
+ }
565
+ PatKind :: Wild |
566
+ PatKind :: Binding ( ..) |
567
+ PatKind :: Ref ( ..) => false ,
568
+ }
569
+ }
570
+
563
571
fn borrow_pat_suggestion (
564
572
& self ,
565
573
err : & mut DiagnosticBuilder < ' _ > ,
0 commit comments