Skip to content

Commit d302413

Browse files
committed
PatKind::Path: avoid calling resolve_ty_and_res_ufcs twice.
1 parent cdd7437 commit d302413

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/librustc_typeck/check/_match.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5050

5151
debug!("check_pat_walk(pat={:?},expected={:?},def_bm={:?})", pat, expected, def_bm);
5252

53+
let mut path_resolution = None;
5354
let is_non_ref_pat = match pat.node {
5455
PatKind::Struct(..) |
5556
PatKind::TupleStruct(..) |
@@ -65,8 +66,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
6566
}
6667
}
6768
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 {
7072
Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssocConst, _) => false,
7173
_ => true,
7274
}
@@ -294,7 +296,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
294296
)
295297
}
296298
PatKind::Path(ref qpath) => {
297-
self.check_pat_path(pat, qpath, expected)
299+
self.check_pat_path(pat, path_resolution.unwrap(), qpath, expected)
298300
}
299301
PatKind::Struct(ref qpath, ref fields, etc) => {
300302
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");
10551057
fn check_pat_path(
10561058
&self,
10571059
pat: &hir::Pat,
1060+
path_resolution: (Res, Option<Ty<'tcx>>, &'b [hir::PathSegment]),
10581061
qpath: &hir::QPath,
10591062
expected: Ty<'tcx>,
10601063
) -> Ty<'tcx> {
10611064
let tcx = self.tcx;
10621065

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;
10651068
match res {
10661069
Res::Err => {
10671070
self.set_tainted_by_errors();

0 commit comments

Comments
 (0)