Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary lifetime from PatInfo. #138377

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 27 additions & 25 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
@@ -87,10 +87,10 @@ struct TopInfo<'tcx> {
}

#[derive(Copy, Clone)]
struct PatInfo<'a, 'tcx> {
struct PatInfo<'tcx> {
binding_mode: ByRef,
max_ref_mutbl: MutblCap,
top_info: &'a TopInfo<'tcx>,
top_info: TopInfo<'tcx>,
decl_origin: Option<DeclOrigin<'tcx>>,

/// The depth of current pattern
@@ -303,11 +303,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
origin_expr: Option<&'tcx hir::Expr<'tcx>>,
decl_origin: Option<DeclOrigin<'tcx>>,
) {
let info = TopInfo { expected, origin_expr, span, hir_id: pat.hir_id };
let top_info = TopInfo { expected, origin_expr, span, hir_id: pat.hir_id };
let pat_info = PatInfo {
binding_mode: ByRef::No,
max_ref_mutbl: MutblCap::Mut,
top_info: &info,
top_info,
decl_origin,
current_depth: 0,
};
@@ -320,7 +320,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Outside of this module, `check_pat_top` should always be used.
/// Conversely, inside this module, `check_pat_top` should never be used.
#[instrument(level = "debug", skip(self, pat_info))]
fn check_pat(&self, pat: &'tcx Pat<'tcx>, expected: Ty<'tcx>, pat_info: PatInfo<'_, 'tcx>) {
fn check_pat(&self, pat: &'tcx Pat<'tcx>, expected: Ty<'tcx>, pat_info: PatInfo<'tcx>) {
let PatInfo { binding_mode, max_ref_mutbl, top_info: ti, current_depth, .. } = pat_info;

let path_res = match pat.kind {
@@ -352,13 +352,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
qpath,
path_res.unwrap(),
expected,
ti,
&pat_info.top_info,
);
self.write_ty(*hir_id, ty);
ty
}
PatKind::Expr(lt) => self.check_pat_lit(pat.span, lt, expected, ti),
PatKind::Range(lhs, rhs, _) => self.check_pat_range(pat.span, lhs, rhs, expected, ti),
PatKind::Expr(lt) => self.check_pat_lit(pat.span, lt, expected, &pat_info.top_info),
PatKind::Range(lhs, rhs, _) => {
self.check_pat_range(pat.span, lhs, rhs, expected, &pat_info.top_info)
}
PatKind::Binding(ba, var_id, ident, sub) => {
self.check_pat_ident(pat, ba, var_id, ident, sub, expected, pat_info)
}
@@ -818,7 +820,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ident: Ident,
sub: Option<&'tcx Pat<'tcx>>,
expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>,
pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
let PatInfo { binding_mode: def_br, top_info: ti, .. } = pat_info;

@@ -914,12 +916,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};

// We have a concrete type for the local, so we do not need to taint it and hide follow up errors *using* the local.
let _ = self.demand_eqtype_pat(pat.span, eq_ty, local_ty, ti);
let _ = self.demand_eqtype_pat(pat.span, eq_ty, local_ty, &ti);

// If there are multiple arms, make sure they all agree on
// what the type of the binding `x` ought to be.
if var_id != pat.hir_id {
self.check_binding_alt_eq_ty(user_bind_annot, pat.span, var_id, local_ty, ti);
self.check_binding_alt_eq_ty(user_bind_annot, pat.span, var_id, local_ty, &ti);
}

if let Some(p) = sub {
@@ -1149,7 +1151,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fields: &'tcx [hir::PatField<'tcx>],
has_rest_pat: bool,
expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>,
pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
// Resolve the path and check the definition for errors.
let (variant, pat_ty) = match self.check_struct_path(qpath, pat.hir_id) {
@@ -1164,7 +1166,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};

// Type-check the path.
let _ = self.demand_eqtype_pat(pat.span, expected, pat_ty, pat_info.top_info);
let _ = self.demand_eqtype_pat(pat.span, expected, pat_ty, &pat_info.top_info);

// Type-check subpatterns.
match self.check_struct_pat_fields(pat_ty, pat, variant, fields, has_rest_pat, pat_info) {
@@ -1353,7 +1355,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
subpats: &'tcx [Pat<'tcx>],
ddpos: hir::DotDotPos,
expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>,
pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
let tcx = self.tcx;
let on_error = |e| {
@@ -1403,7 +1405,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let pat_ty = pat_ty.no_bound_vars().expect("expected fn type");

// Type-check the tuple struct pattern against the expected type.
let diag = self.demand_eqtype_pat_diag(pat.span, expected, pat_ty, pat_info.top_info);
let diag = self.demand_eqtype_pat_diag(pat.span, expected, pat_ty, &pat_info.top_info);
let had_err = diag.map_err(|diag| diag.emit());

// Type-check subpatterns.
@@ -1610,7 +1612,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
elements: &'tcx [Pat<'tcx>],
ddpos: hir::DotDotPos,
expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>,
pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
let tcx = self.tcx;
let mut expected_len = elements.len();
@@ -1625,7 +1627,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let element_tys_iter = (0..max_len).map(|_| self.next_ty_var(span));
let element_tys = tcx.mk_type_list_from_iter(element_tys_iter);
let pat_ty = Ty::new_tup(tcx, element_tys);
if let Err(reported) = self.demand_eqtype_pat(span, expected, pat_ty, pat_info.top_info) {
if let Err(reported) = self.demand_eqtype_pat(span, expected, pat_ty, &pat_info.top_info) {
// Walk subpatterns with an expected type of `err` in this case to silence
// further errors being emitted when using the bindings. #50333
let element_tys_iter = (0..max_len).map(|_| Ty::new_error(tcx, reported));
@@ -1648,7 +1650,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
variant: &'tcx ty::VariantDef,
fields: &'tcx [hir::PatField<'tcx>],
has_rest_pat: bool,
pat_info: PatInfo<'_, 'tcx>,
pat_info: PatInfo<'tcx>,
) -> Result<(), ErrorGuaranteed> {
let tcx = self.tcx;

@@ -2257,7 +2259,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span: Span,
inner: &'tcx Pat<'tcx>,
expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>,
pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
let tcx = self.tcx;
let (box_ty, inner_ty) = self
@@ -2267,7 +2269,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// think any errors can be introduced by using `demand::eqtype`.
let inner_ty = self.next_ty_var(inner.span);
let box_ty = Ty::new_box(tcx, inner_ty);
self.demand_eqtype_pat(span, expected, box_ty, pat_info.top_info)?;
self.demand_eqtype_pat(span, expected, box_ty, &pat_info.top_info)?;
Ok((box_ty, inner_ty))
})
.unwrap_or_else(|guar| {
@@ -2283,7 +2285,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span: Span,
inner: &'tcx Pat<'tcx>,
expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>,
pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
let tcx = self.tcx;
// Register a `DerefPure` bound, which is required by all `deref!()` pats.
@@ -2324,7 +2326,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
inner: &'tcx Pat<'tcx>,
pat_mutbl: Mutability,
mut expected: Ty<'tcx>,
mut pat_info: PatInfo<'_, 'tcx>,
mut pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
let tcx = self.tcx;

@@ -2482,7 +2484,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pat.span,
expected,
ref_ty,
pat_info.top_info,
&pat_info.top_info,
);

// Look for a case like `fn foo(&foo: u32)` and suggest
@@ -2605,7 +2607,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
slice: Option<&'tcx Pat<'tcx>>,
after: &'tcx [Pat<'tcx>],
expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>,
pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
let expected = self.try_structurally_resolve_type(span, expected);

@@ -2767,7 +2769,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
span: Span,
expected_ty: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>,
pat_info: PatInfo<'tcx>,
) -> ErrorGuaranteed {
let PatInfo { top_info: ti, current_depth, .. } = pat_info;

Loading