1
Fork 0

Remove unnecessary lifetime from PatInfo.

This commit is contained in:
Nicholas Nethercote 2025-01-30 13:23:37 +11:00
parent 6650252439
commit c0cee43af5

View file

@ -87,10 +87,10 @@ struct TopInfo<'tcx> {
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
struct PatInfo<'a, 'tcx> { struct PatInfo<'tcx> {
binding_mode: ByRef, binding_mode: ByRef,
max_ref_mutbl: MutblCap, max_ref_mutbl: MutblCap,
top_info: &'a TopInfo<'tcx>, top_info: TopInfo<'tcx>,
decl_origin: Option<DeclOrigin<'tcx>>, decl_origin: Option<DeclOrigin<'tcx>>,
/// The depth of current pattern /// The depth of current pattern
@ -303,11 +303,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
origin_expr: Option<&'tcx hir::Expr<'tcx>>, origin_expr: Option<&'tcx hir::Expr<'tcx>>,
decl_origin: Option<DeclOrigin<'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 { let pat_info = PatInfo {
binding_mode: ByRef::No, binding_mode: ByRef::No,
max_ref_mutbl: MutblCap::Mut, max_ref_mutbl: MutblCap::Mut,
top_info: &info, top_info,
decl_origin, decl_origin,
current_depth: 0, current_depth: 0,
}; };
@ -320,7 +320,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Outside of this module, `check_pat_top` should always be used. /// Outside of this module, `check_pat_top` should always be used.
/// Conversely, inside this module, `check_pat_top` should never be used. /// Conversely, inside this module, `check_pat_top` should never be used.
#[instrument(level = "debug", skip(self, pat_info))] #[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 PatInfo { binding_mode, max_ref_mutbl, top_info: ti, current_depth, .. } = pat_info;
let path_res = match pat.kind { let path_res = match pat.kind {
@ -352,13 +352,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
qpath, qpath,
path_res.unwrap(), path_res.unwrap(),
expected, expected,
ti, &pat_info.top_info,
); );
self.write_ty(*hir_id, ty); self.write_ty(*hir_id, ty);
ty ty
} }
PatKind::Expr(lt) => self.check_pat_lit(pat.span, lt, 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, ti), PatKind::Range(lhs, rhs, _) => {
self.check_pat_range(pat.span, lhs, rhs, expected, &pat_info.top_info)
}
PatKind::Binding(ba, var_id, ident, sub) => { PatKind::Binding(ba, var_id, ident, sub) => {
self.check_pat_ident(pat, ba, var_id, ident, sub, expected, pat_info) 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, ident: Ident,
sub: Option<&'tcx Pat<'tcx>>, sub: Option<&'tcx Pat<'tcx>>,
expected: Ty<'tcx>, expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>, pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
let PatInfo { binding_mode: def_br, top_info: ti, .. } = pat_info; 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. // 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 // If there are multiple arms, make sure they all agree on
// what the type of the binding `x` ought to be. // what the type of the binding `x` ought to be.
if var_id != pat.hir_id { 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 { if let Some(p) = sub {
@ -1149,7 +1151,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fields: &'tcx [hir::PatField<'tcx>], fields: &'tcx [hir::PatField<'tcx>],
has_rest_pat: bool, has_rest_pat: bool,
expected: Ty<'tcx>, expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>, pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
// Resolve the path and check the definition for errors. // Resolve the path and check the definition for errors.
let (variant, pat_ty) = match self.check_struct_path(qpath, pat.hir_id) { 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. // 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. // Type-check subpatterns.
match self.check_struct_pat_fields(pat_ty, pat, variant, fields, has_rest_pat, pat_info) { 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>], subpats: &'tcx [Pat<'tcx>],
ddpos: hir::DotDotPos, ddpos: hir::DotDotPos,
expected: Ty<'tcx>, expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>, pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
let tcx = self.tcx; let tcx = self.tcx;
let on_error = |e| { 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"); let pat_ty = pat_ty.no_bound_vars().expect("expected fn type");
// Type-check the tuple struct pattern against the expected 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()); let had_err = diag.map_err(|diag| diag.emit());
// Type-check subpatterns. // Type-check subpatterns.
@ -1610,7 +1612,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
elements: &'tcx [Pat<'tcx>], elements: &'tcx [Pat<'tcx>],
ddpos: hir::DotDotPos, ddpos: hir::DotDotPos,
expected: Ty<'tcx>, expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>, pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
let tcx = self.tcx; let tcx = self.tcx;
let mut expected_len = elements.len(); 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_iter = (0..max_len).map(|_| self.next_ty_var(span));
let element_tys = tcx.mk_type_list_from_iter(element_tys_iter); let element_tys = tcx.mk_type_list_from_iter(element_tys_iter);
let pat_ty = Ty::new_tup(tcx, element_tys); 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 // Walk subpatterns with an expected type of `err` in this case to silence
// further errors being emitted when using the bindings. #50333 // further errors being emitted when using the bindings. #50333
let element_tys_iter = (0..max_len).map(|_| Ty::new_error(tcx, reported)); 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, variant: &'tcx ty::VariantDef,
fields: &'tcx [hir::PatField<'tcx>], fields: &'tcx [hir::PatField<'tcx>],
has_rest_pat: bool, has_rest_pat: bool,
pat_info: PatInfo<'_, 'tcx>, pat_info: PatInfo<'tcx>,
) -> Result<(), ErrorGuaranteed> { ) -> Result<(), ErrorGuaranteed> {
let tcx = self.tcx; let tcx = self.tcx;
@ -2257,7 +2259,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span: Span, span: Span,
inner: &'tcx Pat<'tcx>, inner: &'tcx Pat<'tcx>,
expected: Ty<'tcx>, expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>, pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
let tcx = self.tcx; let tcx = self.tcx;
let (box_ty, inner_ty) = self 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`. // think any errors can be introduced by using `demand::eqtype`.
let inner_ty = self.next_ty_var(inner.span); let inner_ty = self.next_ty_var(inner.span);
let box_ty = Ty::new_box(tcx, inner_ty); 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)) Ok((box_ty, inner_ty))
}) })
.unwrap_or_else(|guar| { .unwrap_or_else(|guar| {
@ -2283,7 +2285,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span: Span, span: Span,
inner: &'tcx Pat<'tcx>, inner: &'tcx Pat<'tcx>,
expected: Ty<'tcx>, expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>, pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
let tcx = self.tcx; let tcx = self.tcx;
// Register a `DerefPure` bound, which is required by all `deref!()` pats. // 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>, inner: &'tcx Pat<'tcx>,
pat_mutbl: Mutability, pat_mutbl: Mutability,
mut expected: Ty<'tcx>, mut expected: Ty<'tcx>,
mut pat_info: PatInfo<'_, 'tcx>, mut pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
let tcx = self.tcx; let tcx = self.tcx;
@ -2482,7 +2484,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pat.span, pat.span,
expected, expected,
ref_ty, ref_ty,
pat_info.top_info, &pat_info.top_info,
); );
// Look for a case like `fn foo(&foo: u32)` and suggest // 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>>, slice: Option<&'tcx Pat<'tcx>>,
after: &'tcx [Pat<'tcx>], after: &'tcx [Pat<'tcx>],
expected: Ty<'tcx>, expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>, pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
let expected = self.try_structurally_resolve_type(span, expected); let expected = self.try_structurally_resolve_type(span, expected);
@ -2767,7 +2769,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self, &self,
span: Span, span: Span,
expected_ty: Ty<'tcx>, expected_ty: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>, pat_info: PatInfo<'tcx>,
) -> ErrorGuaranteed { ) -> ErrorGuaranteed {
let PatInfo { top_info: ti, current_depth, .. } = pat_info; let PatInfo { top_info: ti, current_depth, .. } = pat_info;