Skip to content

Commit

Permalink
Avoid passing a full Pat when only the Span/HirId is used
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jan 8, 2025
1 parent 9942b77 commit 5df6919
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.check_pat_tuple_struct(pat, qpath, subpats, ddpos, expected, pat_info)
}
PatKind::Path(ref qpath) => {
self.check_pat_path(pat, qpath, path_res.unwrap(), expected, ti)
self.check_pat_path(pat.hir_id, pat.span, qpath, path_res.unwrap(), expected, ti)
}
PatKind::Struct(ref qpath, fields, has_rest_pat) => {
self.check_pat_struct(pat, qpath, fields, has_rest_pat, expected, pat_info)
Expand Down Expand Up @@ -1053,7 +1053,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

fn check_pat_path(
&self,
pat: &Pat<'tcx>,
hir_id: HirId,
span: Span,
qpath: &hir::QPath<'_>,
path_resolution: (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]),
expected: Ty<'tcx>,
Expand All @@ -1072,8 +1073,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
Res::Def(DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fn) | DefKind::Variant, _) => {
let expected = "unit struct, unit variant or constant";
let e =
report_unexpected_variant_res(tcx, res, None, qpath, pat.span, E0533, expected);
let e = report_unexpected_variant_res(tcx, res, None, qpath, span, E0533, expected);
return Ty::new_error(tcx, e);
}
Res::SelfCtor(def_id) => {
Expand All @@ -1088,7 +1088,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
res,
None,
qpath,
pat.span,
span,
E0533,
"unit struct",
);
Expand All @@ -1107,11 +1107,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Type-check the path.
let (pat_ty, pat_res) =
self.instantiate_value_path(segments, opt_ty, res, pat.span, pat.span, pat.hir_id);
self.instantiate_value_path(segments, opt_ty, res, span, span, hir_id);
if let Err(err) =
self.demand_suptype_with_origin(&self.pattern_cause(ti, pat.span), expected, pat_ty)
self.demand_suptype_with_origin(&self.pattern_cause(ti, span), expected, pat_ty)
{
self.emit_bad_pat_path(err, pat, res, pat_res, pat_ty, segments);
self.emit_bad_pat_path(err, hir_id, span, res, pat_res, pat_ty, segments);
}
pat_ty
}
Expand Down Expand Up @@ -1154,13 +1154,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn emit_bad_pat_path(
&self,
mut e: Diag<'_>,
pat: &hir::Pat<'tcx>,
hir_id: HirId,
pat_span: Span,
res: Res,
pat_res: Res,
pat_ty: Ty<'tcx>,
segments: &'tcx [hir::PathSegment<'tcx>],
) {
let pat_span = pat.span;
if let Some(span) = self.tcx.hir().res_span(pat_res) {
e.span_label(span, format!("{} defined here", res.descr()));
if let [hir::PathSegment { ident, .. }] = &*segments {
Expand All @@ -1173,7 +1173,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
res.descr(),
),
);
match self.tcx.parent_hir_node(pat.hir_id) {
match self.tcx.parent_hir_node(hir_id) {
hir::Node::PatField(..) => {
e.span_suggestion_verbose(
ident.span.shrink_to_hi(),
Expand Down

0 comments on commit 5df6919

Please sign in to comment.