Skip to content

Commit df1dbe7

Browse files
authored
Rollup merge of rust-lang#138377 - nnethercote:rustc_hir_typeck, r=compiler-errors
Remove unnecessary lifetime from `PatInfo`. r? ``@jackh726``
2 parents acfc84d + c0cee43 commit df1dbe7

File tree

1 file changed

+27
-25
lines changed
  • compiler/rustc_hir_typeck/src

1 file changed

+27
-25
lines changed

compiler/rustc_hir_typeck/src/pat.rs

+27-25
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 {
@@ -352,13 +352,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
352352
qpath,
353353
path_res.unwrap(),
354354
expected,
355-
ti,
355+
&pat_info.top_info,
356356
);
357357
self.write_ty(*hir_id, ty);
358358
ty
359359
}
360-
PatKind::Expr(lt) => self.check_pat_lit(pat.span, lt, expected, ti),
361-
PatKind::Range(lhs, rhs, _) => self.check_pat_range(pat.span, lhs, rhs, expected, ti),
360+
PatKind::Expr(lt) => self.check_pat_lit(pat.span, lt, expected, &pat_info.top_info),
361+
PatKind::Range(lhs, rhs, _) => {
362+
self.check_pat_range(pat.span, lhs, rhs, expected, &pat_info.top_info)
363+
}
362364
PatKind::Binding(ba, var_id, ident, sub) => {
363365
self.check_pat_ident(pat, ba, var_id, ident, sub, expected, pat_info)
364366
}
@@ -818,7 +820,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
818820
ident: Ident,
819821
sub: Option<&'tcx Pat<'tcx>>,
820822
expected: Ty<'tcx>,
821-
pat_info: PatInfo<'_, 'tcx>,
823+
pat_info: PatInfo<'tcx>,
822824
) -> Ty<'tcx> {
823825
let PatInfo { binding_mode: def_br, top_info: ti, .. } = pat_info;
824826

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

916918
// 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);
919+
let _ = self.demand_eqtype_pat(pat.span, eq_ty, local_ty, &ti);
918920

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

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

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

11691171
// Type-check subpatterns.
11701172
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> {
13531355
subpats: &'tcx [Pat<'tcx>],
13541356
ddpos: hir::DotDotPos,
13551357
expected: Ty<'tcx>,
1356-
pat_info: PatInfo<'_, 'tcx>,
1358+
pat_info: PatInfo<'tcx>,
13571359
) -> Ty<'tcx> {
13581360
let tcx = self.tcx;
13591361
let on_error = |e| {
@@ -1403,7 +1405,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14031405
let pat_ty = pat_ty.no_bound_vars().expect("expected fn type");
14041406

14051407
// 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);
1408+
let diag = self.demand_eqtype_pat_diag(pat.span, expected, pat_ty, &pat_info.top_info);
14071409
let had_err = diag.map_err(|diag| diag.emit());
14081410

14091411
// Type-check subpatterns.
@@ -1610,7 +1612,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16101612
elements: &'tcx [Pat<'tcx>],
16111613
ddpos: hir::DotDotPos,
16121614
expected: Ty<'tcx>,
1613-
pat_info: PatInfo<'_, 'tcx>,
1615+
pat_info: PatInfo<'tcx>,
16141616
) -> Ty<'tcx> {
16151617
let tcx = self.tcx;
16161618
let mut expected_len = elements.len();
@@ -1625,7 +1627,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16251627
let element_tys_iter = (0..max_len).map(|_| self.next_ty_var(span));
16261628
let element_tys = tcx.mk_type_list_from_iter(element_tys_iter);
16271629
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) {
1630+
if let Err(reported) = self.demand_eqtype_pat(span, expected, pat_ty, &pat_info.top_info) {
16291631
// Walk subpatterns with an expected type of `err` in this case to silence
16301632
// further errors being emitted when using the bindings. #50333
16311633
let element_tys_iter = (0..max_len).map(|_| Ty::new_error(tcx, reported));
@@ -1648,7 +1650,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16481650
variant: &'tcx ty::VariantDef,
16491651
fields: &'tcx [hir::PatField<'tcx>],
16501652
has_rest_pat: bool,
1651-
pat_info: PatInfo<'_, 'tcx>,
1653+
pat_info: PatInfo<'tcx>,
16521654
) -> Result<(), ErrorGuaranteed> {
16531655
let tcx = self.tcx;
16541656

@@ -2257,7 +2259,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22572259
span: Span,
22582260
inner: &'tcx Pat<'tcx>,
22592261
expected: Ty<'tcx>,
2260-
pat_info: PatInfo<'_, 'tcx>,
2262+
pat_info: PatInfo<'tcx>,
22612263
) -> Ty<'tcx> {
22622264
let tcx = self.tcx;
22632265
let (box_ty, inner_ty) = self
@@ -2267,7 +2269,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22672269
// think any errors can be introduced by using `demand::eqtype`.
22682270
let inner_ty = self.next_ty_var(inner.span);
22692271
let box_ty = Ty::new_box(tcx, inner_ty);
2270-
self.demand_eqtype_pat(span, expected, box_ty, pat_info.top_info)?;
2272+
self.demand_eqtype_pat(span, expected, box_ty, &pat_info.top_info)?;
22712273
Ok((box_ty, inner_ty))
22722274
})
22732275
.unwrap_or_else(|guar| {
@@ -2283,7 +2285,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22832285
span: Span,
22842286
inner: &'tcx Pat<'tcx>,
22852287
expected: Ty<'tcx>,
2286-
pat_info: PatInfo<'_, 'tcx>,
2288+
pat_info: PatInfo<'tcx>,
22872289
) -> Ty<'tcx> {
22882290
let tcx = self.tcx;
22892291
// Register a `DerefPure` bound, which is required by all `deref!()` pats.
@@ -2324,7 +2326,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23242326
inner: &'tcx Pat<'tcx>,
23252327
pat_mutbl: Mutability,
23262328
mut expected: Ty<'tcx>,
2327-
mut pat_info: PatInfo<'_, 'tcx>,
2329+
mut pat_info: PatInfo<'tcx>,
23282330
) -> Ty<'tcx> {
23292331
let tcx = self.tcx;
23302332

@@ -2482,7 +2484,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24822484
pat.span,
24832485
expected,
24842486
ref_ty,
2485-
pat_info.top_info,
2487+
&pat_info.top_info,
24862488
);
24872489

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

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

0 commit comments

Comments
 (0)