@@ -50,6 +50,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
50
50
51
51
debug ! ( "check_pat_walk(pat={:?},expected={:?},def_bm={:?})" , pat, expected, def_bm) ;
52
52
53
+ let mut path_resolution = None ;
53
54
let is_non_ref_pat = match pat. node {
54
55
PatKind :: Struct ( ..) |
55
56
PatKind :: TupleStruct ( ..) |
@@ -65,8 +66,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
65
66
}
66
67
}
67
68
PatKind :: Path ( ref qpath) => {
68
- let ( def, _, _) = self . resolve_ty_and_res_ufcs ( qpath, pat. hir_id , pat. span ) ;
69
- match def {
69
+ let resolution = self . resolve_ty_and_res_ufcs ( qpath, pat. hir_id , pat. span ) ;
70
+ path_resolution = Some ( resolution) ;
71
+ match resolution. 0 {
70
72
Res :: Def ( DefKind :: Const , _) | Res :: Def ( DefKind :: AssocConst , _) => false ,
71
73
_ => true ,
72
74
}
@@ -294,7 +296,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
294
296
)
295
297
}
296
298
PatKind :: Path ( ref qpath) => {
297
- self . check_pat_path ( pat, qpath, expected)
299
+ self . check_pat_path ( pat, path_resolution . unwrap ( ) , qpath, expected)
298
300
}
299
301
PatKind :: Struct ( ref qpath, ref fields, etc) => {
300
302
self . check_pat_struct ( pat, qpath, fields, etc, expected, def_bm, discrim_span)
@@ -1055,13 +1057,14 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
1055
1057
fn check_pat_path (
1056
1058
& self ,
1057
1059
pat : & hir:: Pat ,
1060
+ path_resolution : ( Res , Option < Ty < ' tcx > > , & ' b [ hir:: PathSegment ] ) ,
1058
1061
qpath : & hir:: QPath ,
1059
1062
expected : Ty < ' tcx > ,
1060
1063
) -> Ty < ' tcx > {
1061
1064
let tcx = self . tcx ;
1062
1065
1063
- // Resolve the path and check the definition for errors .
1064
- let ( res, opt_ty, segments) = self . resolve_ty_and_res_ufcs ( qpath , pat . hir_id , pat . span ) ;
1066
+ // We have already resolved the path .
1067
+ let ( res, opt_ty, segments) = path_resolution ;
1065
1068
match res {
1066
1069
Res :: Err => {
1067
1070
self . set_tainted_by_errors ( ) ;
0 commit comments