mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Avoid passing a full Pat when only the Span/HirId is used
This commit is contained in:
parent
9942b77c5b
commit
5df69191cb
@ -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)
|
||||
@ -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>,
|
||||
@ -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) => {
|
||||
@ -1088,7 +1088,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
res,
|
||||
None,
|
||||
qpath,
|
||||
pat.span,
|
||||
span,
|
||||
E0533,
|
||||
"unit struct",
|
||||
);
|
||||
@ -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
|
||||
}
|
||||
@ -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 {
|
||||
@ -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(),
|
||||
|
Loading…
Reference in New Issue
Block a user