Skip to content

Commit 637ded1

Browse files
committed
Avoid passing a full Pat when only the Span/HirId is used
1 parent 643fdbd commit 637ded1

File tree

1 file changed

+11
-11
lines changed
  • compiler/rustc_hir_typeck/src

1 file changed

+11
-11
lines changed

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
254254
self.check_pat_tuple_struct(pat, qpath, subpats, ddpos, expected, pat_info)
255255
}
256256
PatKind::Path(ref qpath) => {
257-
self.check_pat_path(pat, qpath, path_res.unwrap(), expected, ti)
257+
self.check_pat_path(pat.hir_id, pat.span, qpath, path_res.unwrap(), expected, ti)
258258
}
259259
PatKind::Struct(ref qpath, fields, has_rest_pat) => {
260260
self.check_pat_struct(pat, qpath, fields, has_rest_pat, expected, pat_info)
@@ -1020,7 +1020,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10201020

10211021
fn check_pat_path(
10221022
&self,
1023-
pat: &Pat<'tcx>,
1023+
hir_id: HirId,
1024+
span: Span,
10241025
qpath: &hir::QPath<'_>,
10251026
path_resolution: (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]),
10261027
expected: Ty<'tcx>,
@@ -1039,8 +1040,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10391040
}
10401041
Res::Def(DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fn) | DefKind::Variant, _) => {
10411042
let expected = "unit struct, unit variant or constant";
1042-
let e =
1043-
report_unexpected_variant_res(tcx, res, None, qpath, pat.span, E0533, expected);
1043+
let e = report_unexpected_variant_res(tcx, res, None, qpath, span, E0533, expected);
10441044
return Ty::new_error(tcx, e);
10451045
}
10461046
Res::SelfCtor(def_id) => {
@@ -1055,7 +1055,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10551055
res,
10561056
None,
10571057
qpath,
1058-
pat.span,
1058+
span,
10591059
E0533,
10601060
"unit struct",
10611061
);
@@ -1074,11 +1074,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10741074

10751075
// Type-check the path.
10761076
let (pat_ty, pat_res) =
1077-
self.instantiate_value_path(segments, opt_ty, res, pat.span, pat.span, pat.hir_id);
1077+
self.instantiate_value_path(segments, opt_ty, res, span, span, hir_id);
10781078
if let Err(err) =
1079-
self.demand_suptype_with_origin(&self.pattern_cause(ti, pat.span), expected, pat_ty)
1079+
self.demand_suptype_with_origin(&self.pattern_cause(ti, span), expected, pat_ty)
10801080
{
1081-
self.emit_bad_pat_path(err, pat, res, pat_res, pat_ty, segments);
1081+
self.emit_bad_pat_path(err, hir_id, span, res, pat_res, pat_ty, segments);
10821082
}
10831083
pat_ty
10841084
}
@@ -1121,13 +1121,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11211121
fn emit_bad_pat_path(
11221122
&self,
11231123
mut e: Diag<'_>,
1124-
pat: &hir::Pat<'tcx>,
1124+
hir_id: HirId,
1125+
pat_span: Span,
11251126
res: Res,
11261127
pat_res: Res,
11271128
pat_ty: Ty<'tcx>,
11281129
segments: &'tcx [hir::PathSegment<'tcx>],
11291130
) {
1130-
let pat_span = pat.span;
11311131
if let Some(span) = self.tcx.hir().res_span(pat_res) {
11321132
e.span_label(span, format!("{} defined here", res.descr()));
11331133
if let [hir::PathSegment { ident, .. }] = &*segments {
@@ -1140,7 +1140,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11401140
res.descr(),
11411141
),
11421142
);
1143-
match self.tcx.parent_hir_node(pat.hir_id) {
1143+
match self.tcx.parent_hir_node(hir_id) {
11441144
hir::Node::PatField(..) => {
11451145
e.span_suggestion_verbose(
11461146
ident.span.shrink_to_hi(),

0 commit comments

Comments
 (0)