Skip to content

Commit 044ce57

Browse files
committed
Avoid passing a full Pat when only the Span/HirId is used
1 parent 56c2469 commit 044ce57

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
279279
self.check_pat_tuple_struct(pat, qpath, subpats, ddpos, expected, pat_info)
280280
}
281281
PatKind::Path(ref qpath) => {
282-
self.check_pat_path(pat, qpath, path_res.unwrap(), expected, ti)
282+
self.check_pat_path(pat.hir_id, pat.span, qpath, path_res.unwrap(), expected, ti)
283283
}
284284
PatKind::Struct(ref qpath, fields, has_rest_pat) => {
285285
self.check_pat_struct(pat, qpath, fields, has_rest_pat, expected, pat_info)
@@ -1045,7 +1045,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10451045

10461046
fn check_pat_path(
10471047
&self,
1048-
pat: &Pat<'tcx>,
1048+
hir_id: HirId,
1049+
span: Span,
10491050
qpath: &hir::QPath<'_>,
10501051
path_resolution: (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]),
10511052
expected: Ty<'tcx>,
@@ -1064,8 +1065,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10641065
}
10651066
Res::Def(DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fn) | DefKind::Variant, _) => {
10661067
let expected = "unit struct, unit variant or constant";
1067-
let e =
1068-
report_unexpected_variant_res(tcx, res, None, qpath, pat.span, E0533, expected);
1068+
let e = report_unexpected_variant_res(tcx, res, None, qpath, span, E0533, expected);
10691069
return Ty::new_error(tcx, e);
10701070
}
10711071
Res::SelfCtor(def_id) => {
@@ -1080,7 +1080,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10801080
res,
10811081
None,
10821082
qpath,
1083-
pat.span,
1083+
span,
10841084
E0533,
10851085
"unit struct",
10861086
);
@@ -1099,11 +1099,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10991099

11001100
// Type-check the path.
11011101
let (pat_ty, pat_res) =
1102-
self.instantiate_value_path(segments, opt_ty, res, pat.span, pat.span, pat.hir_id);
1102+
self.instantiate_value_path(segments, opt_ty, res, span, span, hir_id);
11031103
if let Err(err) =
1104-
self.demand_suptype_with_origin(&self.pattern_cause(ti, pat.span), expected, pat_ty)
1104+
self.demand_suptype_with_origin(&self.pattern_cause(ti, span), expected, pat_ty)
11051105
{
1106-
self.emit_bad_pat_path(err, pat, res, pat_res, pat_ty, segments);
1106+
self.emit_bad_pat_path(err, hir_id, span, res, pat_res, pat_ty, segments);
11071107
}
11081108
pat_ty
11091109
}
@@ -1146,13 +1146,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11461146
fn emit_bad_pat_path(
11471147
&self,
11481148
mut e: Diag<'_>,
1149-
pat: &hir::Pat<'tcx>,
1149+
hir_id: HirId,
1150+
pat_span: Span,
11501151
res: Res,
11511152
pat_res: Res,
11521153
pat_ty: Ty<'tcx>,
11531154
segments: &'tcx [hir::PathSegment<'tcx>],
11541155
) {
1155-
let pat_span = pat.span;
11561156
if let Some(span) = self.tcx.hir().res_span(pat_res) {
11571157
e.span_label(span, format!("{} defined here", res.descr()));
11581158
if let [hir::PathSegment { ident, .. }] = &*segments {
@@ -1165,7 +1165,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11651165
res.descr(),
11661166
),
11671167
);
1168-
match self.tcx.parent_hir_node(pat.hir_id) {
1168+
match self.tcx.parent_hir_node(hir_id) {
11691169
hir::Node::PatField(..) => {
11701170
e.span_suggestion_verbose(
11711171
ident.span.shrink_to_hi(),

0 commit comments

Comments
 (0)