Skip to content

Commit 7382b20

Browse files
committed
Remove unnecessary lifetime from PatInfo.
1 parent 6650252 commit 7382b20

File tree

1 file changed

+23
-22
lines changed
  • compiler/rustc_hir_typeck/src

1 file changed

+23
-22
lines changed

compiler/rustc_hir_typeck/src/pat.rs

+23-22
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ struct TopInfo<'tcx> {
8787
}
8888

8989
#[derive(Copy, Clone)]
90-
struct PatInfo<'a, 'tcx> {
90+
struct PatInfo<'tcx> {
9191
binding_mode: ByRef,
9292
max_ref_mutbl: MutblCap,
93-
top_info: &'a TopInfo<'tcx>,
93+
top_info: TopInfo<'tcx>,
9494
decl_origin: Option<DeclOrigin<'tcx>>,
9595

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

326326
let path_res = match pat.kind {
@@ -339,6 +339,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
339339
decl_origin: pat_info.decl_origin,
340340
current_depth: current_depth + 1,
341341
};
342+
let ti = &pat_info.top_info;
342343

343344
let ty = match pat.kind {
344345
PatKind::Wild | PatKind::Err(_) => expected,
@@ -818,7 +819,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
818819
ident: Ident,
819820
sub: Option<&'tcx Pat<'tcx>>,
820821
expected: Ty<'tcx>,
821-
pat_info: PatInfo<'_, 'tcx>,
822+
pat_info: PatInfo<'tcx>,
822823
) -> Ty<'tcx> {
823824
let PatInfo { binding_mode: def_br, top_info: ti, .. } = pat_info;
824825

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

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

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

925926
if let Some(p) = sub {
@@ -1149,7 +1150,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11491150
fields: &'tcx [hir::PatField<'tcx>],
11501151
has_rest_pat: bool,
11511152
expected: Ty<'tcx>,
1152-
pat_info: PatInfo<'_, 'tcx>,
1153+
pat_info: PatInfo<'tcx>,
11531154
) -> Ty<'tcx> {
11541155
// Resolve the path and check the definition for errors.
11551156
let (variant, pat_ty) = match self.check_struct_path(qpath, pat.hir_id) {
@@ -1164,7 +1165,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11641165
};
11651166

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

11691170
// Type-check subpatterns.
11701171
match self.check_struct_pat_fields(pat_ty, pat, variant, fields, has_rest_pat, pat_info) {
@@ -1353,7 +1354,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13531354
subpats: &'tcx [Pat<'tcx>],
13541355
ddpos: hir::DotDotPos,
13551356
expected: Ty<'tcx>,
1356-
pat_info: PatInfo<'_, 'tcx>,
1357+
pat_info: PatInfo<'tcx>,
13571358
) -> Ty<'tcx> {
13581359
let tcx = self.tcx;
13591360
let on_error = |e| {
@@ -1403,7 +1404,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14031404
let pat_ty = pat_ty.no_bound_vars().expect("expected fn type");
14041405

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

14091410
// Type-check subpatterns.
@@ -1610,7 +1611,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16101611
elements: &'tcx [Pat<'tcx>],
16111612
ddpos: hir::DotDotPos,
16121613
expected: Ty<'tcx>,
1613-
pat_info: PatInfo<'_, 'tcx>,
1614+
pat_info: PatInfo<'tcx>,
16141615
) -> Ty<'tcx> {
16151616
let tcx = self.tcx;
16161617
let mut expected_len = elements.len();
@@ -1625,7 +1626,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16251626
let element_tys_iter = (0..max_len).map(|_| self.next_ty_var(span));
16261627
let element_tys = tcx.mk_type_list_from_iter(element_tys_iter);
16271628
let pat_ty = Ty::new_tup(tcx, element_tys);
1628-
if let Err(reported) = self.demand_eqtype_pat(span, expected, pat_ty, pat_info.top_info) {
1629+
if let Err(reported) = self.demand_eqtype_pat(span, expected, pat_ty, &pat_info.top_info) {
16291630
// Walk subpatterns with an expected type of `err` in this case to silence
16301631
// further errors being emitted when using the bindings. #50333
16311632
let element_tys_iter = (0..max_len).map(|_| Ty::new_error(tcx, reported));
@@ -1648,7 +1649,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16481649
variant: &'tcx ty::VariantDef,
16491650
fields: &'tcx [hir::PatField<'tcx>],
16501651
has_rest_pat: bool,
1651-
pat_info: PatInfo<'_, 'tcx>,
1652+
pat_info: PatInfo<'tcx>,
16521653
) -> Result<(), ErrorGuaranteed> {
16531654
let tcx = self.tcx;
16541655

@@ -2257,7 +2258,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22572258
span: Span,
22582259
inner: &'tcx Pat<'tcx>,
22592260
expected: Ty<'tcx>,
2260-
pat_info: PatInfo<'_, 'tcx>,
2261+
pat_info: PatInfo<'tcx>,
22612262
) -> Ty<'tcx> {
22622263
let tcx = self.tcx;
22632264
let (box_ty, inner_ty) = self
@@ -2267,7 +2268,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22672268
// think any errors can be introduced by using `demand::eqtype`.
22682269
let inner_ty = self.next_ty_var(inner.span);
22692270
let box_ty = Ty::new_box(tcx, inner_ty);
2270-
self.demand_eqtype_pat(span, expected, box_ty, pat_info.top_info)?;
2271+
self.demand_eqtype_pat(span, expected, box_ty, &pat_info.top_info)?;
22712272
Ok((box_ty, inner_ty))
22722273
})
22732274
.unwrap_or_else(|guar| {
@@ -2283,7 +2284,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22832284
span: Span,
22842285
inner: &'tcx Pat<'tcx>,
22852286
expected: Ty<'tcx>,
2286-
pat_info: PatInfo<'_, 'tcx>,
2287+
pat_info: PatInfo<'tcx>,
22872288
) -> Ty<'tcx> {
22882289
let tcx = self.tcx;
22892290
// Register a `DerefPure` bound, which is required by all `deref!()` pats.
@@ -2324,7 +2325,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23242325
inner: &'tcx Pat<'tcx>,
23252326
pat_mutbl: Mutability,
23262327
mut expected: Ty<'tcx>,
2327-
mut pat_info: PatInfo<'_, 'tcx>,
2328+
mut pat_info: PatInfo<'tcx>,
23282329
) -> Ty<'tcx> {
23292330
let tcx = self.tcx;
23302331

@@ -2482,7 +2483,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24822483
pat.span,
24832484
expected,
24842485
ref_ty,
2485-
pat_info.top_info,
2486+
&pat_info.top_info,
24862487
);
24872488

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

@@ -2767,7 +2768,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27672768
&self,
27682769
span: Span,
27692770
expected_ty: Ty<'tcx>,
2770-
pat_info: PatInfo<'_, 'tcx>,
2771+
pat_info: PatInfo<'tcx>,
27712772
) -> ErrorGuaranteed {
27722773
let PatInfo { top_info: ti, current_depth, .. } = pat_info;
27732774

0 commit comments

Comments
 (0)