Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e1be642

Browse files
authoredDec 26, 2023
Rollup merge of rust-lang#119307 - compiler-errors:pat-lifetimes, r=Nadrieril
Clean up some lifetimes in `rustc_pattern_analysis` This PR removes some redundant lifetimes. I figured out that we were shortening the lifetime of an arena-allocated `&'p DeconstructedPat<'p>` to `'a DeconstructedPat<'p>`, which forced us to carry both lifetimes when we could otherwise carry just one. This PR also removes and elides some unnecessary lifetimes. I also cherry-picked 0292eb9, and then simplified more lifetimes in `MatchVisitor`, which should make rust-lang#119233 a very simple PR! r? Nadrieril
2 parents 65aaece + 48d089a commit e1be642

File tree

10 files changed

+111
-104
lines changed

10 files changed

+111
-104
lines changed
 

‎compiler/rustc_middle/src/thir/visit.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ use super::{
33
PatKind, Stmt, StmtKind, Thir,
44
};
55

6-
pub trait Visitor<'a, 'tcx: 'a>: Sized {
7-
fn thir(&self) -> &'a Thir<'tcx>;
6+
pub trait Visitor<'thir, 'tcx: 'thir>: Sized {
7+
fn thir(&self) -> &'thir Thir<'tcx>;
88

9-
fn visit_expr(&mut self, expr: &Expr<'tcx>) {
9+
fn visit_expr(&mut self, expr: &'thir Expr<'tcx>) {
1010
walk_expr(self, expr);
1111
}
1212

13-
fn visit_stmt(&mut self, stmt: &Stmt<'tcx>) {
13+
fn visit_stmt(&mut self, stmt: &'thir Stmt<'tcx>) {
1414
walk_stmt(self, stmt);
1515
}
1616

17-
fn visit_block(&mut self, block: &Block) {
17+
fn visit_block(&mut self, block: &'thir Block) {
1818
walk_block(self, block);
1919
}
2020

21-
fn visit_arm(&mut self, arm: &Arm<'tcx>) {
21+
fn visit_arm(&mut self, arm: &'thir Arm<'tcx>) {
2222
walk_arm(self, arm);
2323
}
2424

25-
fn visit_pat(&mut self, pat: &Pat<'tcx>) {
25+
fn visit_pat(&mut self, pat: &'thir Pat<'tcx>) {
2626
walk_pat(self, pat);
2727
}
2828

@@ -36,7 +36,10 @@ pub trait Visitor<'a, 'tcx: 'a>: Sized {
3636
// other `visit*` functions.
3737
}
3838

39-
pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Expr<'tcx>) {
39+
pub fn walk_expr<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
40+
visitor: &mut V,
41+
expr: &'thir Expr<'tcx>,
42+
) {
4043
use ExprKind::*;
4144
match expr.kind {
4245
Scope { value, region_scope: _, lint_level: _ } => {
@@ -168,7 +171,10 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
168171
}
169172
}
170173

171-
pub fn walk_stmt<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, stmt: &Stmt<'tcx>) {
174+
pub fn walk_stmt<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
175+
visitor: &mut V,
176+
stmt: &'thir Stmt<'tcx>,
177+
) {
172178
match &stmt.kind {
173179
StmtKind::Expr { expr, scope: _ } => visitor.visit_expr(&visitor.thir()[*expr]),
174180
StmtKind::Let {
@@ -191,7 +197,10 @@ pub fn walk_stmt<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, stmt: &Stm
191197
}
192198
}
193199

194-
pub fn walk_block<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, block: &Block) {
200+
pub fn walk_block<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
201+
visitor: &mut V,
202+
block: &'thir Block,
203+
) {
195204
for &stmt in &*block.stmts {
196205
visitor.visit_stmt(&visitor.thir()[stmt]);
197206
}
@@ -200,7 +209,10 @@ pub fn walk_block<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, block: &B
200209
}
201210
}
202211

203-
pub fn walk_arm<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, arm: &Arm<'tcx>) {
212+
pub fn walk_arm<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
213+
visitor: &mut V,
214+
arm: &'thir Arm<'tcx>,
215+
) {
204216
match arm.guard {
205217
Some(Guard::If(expr)) => visitor.visit_expr(&visitor.thir()[expr]),
206218
Some(Guard::IfLet(ref pat, expr)) => {
@@ -213,7 +225,10 @@ pub fn walk_arm<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, arm: &Arm<'
213225
visitor.visit_expr(&visitor.thir()[arm.body]);
214226
}
215227

216-
pub fn walk_pat<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, pat: &Pat<'tcx>) {
228+
pub fn walk_pat<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
229+
visitor: &mut V,
230+
pat: &'thir Pat<'tcx>,
231+
) {
217232
use PatKind::*;
218233
match &pat.kind {
219234
AscribeUserType { subpattern, ascription: _ }

‎compiler/rustc_mir_build/src/check_unsafety.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for LayoutConstrainedPlaceVisitor<'a, 'tcx> {
175175
self.thir
176176
}
177177

178-
fn visit_expr(&mut self, expr: &Expr<'tcx>) {
178+
fn visit_expr(&mut self, expr: &'a Expr<'tcx>) {
179179
match expr.kind {
180180
ExprKind::Field { lhs, .. } => {
181181
if let ty::Adt(adt_def, _) = self.thir[lhs].ty.kind() {
@@ -206,7 +206,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
206206
self.thir
207207
}
208208

209-
fn visit_block(&mut self, block: &Block) {
209+
fn visit_block(&mut self, block: &'a Block) {
210210
match block.safety_mode {
211211
// compiler-generated unsafe code should not count towards the usefulness of
212212
// an outer unsafe block
@@ -234,7 +234,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
234234
}
235235
}
236236

237-
fn visit_pat(&mut self, pat: &Pat<'tcx>) {
237+
fn visit_pat(&mut self, pat: &'a Pat<'tcx>) {
238238
if self.in_union_destructure {
239239
match pat.kind {
240240
// binding to a variable allows getting stuff out of variable
@@ -319,7 +319,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
319319
}
320320
}
321321

322-
fn visit_expr(&mut self, expr: &Expr<'tcx>) {
322+
fn visit_expr(&mut self, expr: &'a Expr<'tcx>) {
323323
// could we be in the LHS of an assignment to a field?
324324
match expr.kind {
325325
ExprKind::Field { .. }

‎compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ enum LetSource {
7575
WhileLet,
7676
}
7777

78-
struct MatchVisitor<'thir, 'p, 'tcx> {
78+
struct MatchVisitor<'p, 'tcx> {
7979
tcx: TyCtxt<'tcx>,
8080
param_env: ty::ParamEnv<'tcx>,
8181
typeck_results: &'tcx ty::TypeckResults<'tcx>,
82-
thir: &'thir Thir<'tcx>,
82+
thir: &'p Thir<'tcx>,
8383
lint_level: HirId,
8484
let_source: LetSource,
8585
pattern_arena: &'p TypedArena<DeconstructedPat<'p, 'tcx>>,
@@ -92,13 +92,13 @@ struct MatchVisitor<'thir, 'p, 'tcx> {
9292

9393
// Visitor for a thir body. This calls `check_match`, `check_let` and `check_let_chain` as
9494
// appropriate.
95-
impl<'thir, 'tcx> Visitor<'thir, 'tcx> for MatchVisitor<'thir, '_, 'tcx> {
96-
fn thir(&self) -> &'thir Thir<'tcx> {
95+
impl<'p, 'tcx> Visitor<'p, 'tcx> for MatchVisitor<'p, 'tcx> {
96+
fn thir(&self) -> &'p Thir<'tcx> {
9797
self.thir
9898
}
9999

100100
#[instrument(level = "trace", skip(self))]
101-
fn visit_arm(&mut self, arm: &Arm<'tcx>) {
101+
fn visit_arm(&mut self, arm: &'p Arm<'tcx>) {
102102
self.with_lint_level(arm.lint_level, |this| {
103103
match arm.guard {
104104
Some(Guard::If(expr)) => {
@@ -121,7 +121,7 @@ impl<'thir, 'tcx> Visitor<'thir, 'tcx> for MatchVisitor<'thir, '_, 'tcx> {
121121
}
122122

123123
#[instrument(level = "trace", skip(self))]
124-
fn visit_expr(&mut self, ex: &Expr<'tcx>) {
124+
fn visit_expr(&mut self, ex: &'p Expr<'tcx>) {
125125
match ex.kind {
126126
ExprKind::Scope { value, lint_level, .. } => {
127127
self.with_lint_level(lint_level, |this| {
@@ -174,7 +174,7 @@ impl<'thir, 'tcx> Visitor<'thir, 'tcx> for MatchVisitor<'thir, '_, 'tcx> {
174174
self.with_let_source(LetSource::None, |this| visit::walk_expr(this, ex));
175175
}
176176

177-
fn visit_stmt(&mut self, stmt: &Stmt<'tcx>) {
177+
fn visit_stmt(&mut self, stmt: &'p Stmt<'tcx>) {
178178
match stmt.kind {
179179
StmtKind::Let {
180180
box ref pattern, initializer, else_block, lint_level, span, ..
@@ -195,7 +195,7 @@ impl<'thir, 'tcx> Visitor<'thir, 'tcx> for MatchVisitor<'thir, '_, 'tcx> {
195195
}
196196
}
197197

198-
impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
198+
impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
199199
#[instrument(level = "trace", skip(self, f))]
200200
fn with_let_source(&mut self, let_source: LetSource, f: impl FnOnce(&mut Self)) {
201201
let old_let_source = self.let_source;
@@ -224,7 +224,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
224224
/// subexpressions we are not handling ourselves.
225225
fn visit_land(
226226
&mut self,
227-
ex: &Expr<'tcx>,
227+
ex: &'p Expr<'tcx>,
228228
accumulator: &mut Vec<Option<(Span, RefutableFlag)>>,
229229
) -> Result<(), ErrorGuaranteed> {
230230
match ex.kind {
@@ -251,7 +251,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
251251
/// expression. This must call `visit_expr` on the subexpressions we are not handling ourselves.
252252
fn visit_land_rhs(
253253
&mut self,
254-
ex: &Expr<'tcx>,
254+
ex: &'p Expr<'tcx>,
255255
) -> Result<Option<(Span, RefutableFlag)>, ErrorGuaranteed> {
256256
match ex.kind {
257257
ExprKind::Scope { value, lint_level, .. } => {
@@ -276,7 +276,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
276276
fn lower_pattern(
277277
&mut self,
278278
cx: &MatchCheckCtxt<'p, 'tcx>,
279-
pat: &Pat<'tcx>,
279+
pat: &'p Pat<'tcx>,
280280
) -> Result<&'p DeconstructedPat<'p, 'tcx>, ErrorGuaranteed> {
281281
if let Err(err) = pat.pat_error_reported() {
282282
self.error = Err(err);
@@ -395,7 +395,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
395395
}
396396

397397
#[instrument(level = "trace", skip(self))]
398-
fn check_let(&mut self, pat: &Pat<'tcx>, scrutinee: Option<ExprId>, span: Span) {
398+
fn check_let(&mut self, pat: &'p Pat<'tcx>, scrutinee: Option<ExprId>, span: Span) {
399399
assert!(self.let_source != LetSource::None);
400400
let scrut = scrutinee.map(|id| &self.thir[id]);
401401
if let LetSource::PlainLet = self.let_source {
@@ -547,7 +547,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
547547

548548
fn analyze_binding(
549549
&mut self,
550-
pat: &Pat<'tcx>,
550+
pat: &'p Pat<'tcx>,
551551
refutability: RefutableFlag,
552552
scrut: Option<&Expr<'tcx>>,
553553
) -> Result<(MatchCheckCtxt<'p, 'tcx>, UsefulnessReport<'p, 'tcx>), ErrorGuaranteed> {
@@ -560,7 +560,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
560560

561561
fn is_let_irrefutable(
562562
&mut self,
563-
pat: &Pat<'tcx>,
563+
pat: &'p Pat<'tcx>,
564564
scrut: Option<&Expr<'tcx>>,
565565
) -> Result<RefutableFlag, ErrorGuaranteed> {
566566
let (cx, report) = self.analyze_binding(pat, Refutable, scrut)?;
@@ -575,7 +575,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
575575
#[instrument(level = "trace", skip(self))]
576576
fn check_binding_is_irrefutable(
577577
&mut self,
578-
pat: &Pat<'tcx>,
578+
pat: &'p Pat<'tcx>,
579579
origin: &str,
580580
scrut: Option<&Expr<'tcx>>,
581581
sp: Option<Span>,
@@ -677,7 +677,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
677677
/// - `x @ Some(ref mut? y)`.
678678
///
679679
/// This analysis is *not* subsumed by NLL.
680-
fn check_borrow_conflicts_in_at_patterns<'tcx>(cx: &MatchVisitor<'_, '_, 'tcx>, pat: &Pat<'tcx>) {
680+
fn check_borrow_conflicts_in_at_patterns<'tcx>(cx: &MatchVisitor<'_, 'tcx>, pat: &Pat<'tcx>) {
681681
// Extract `sub` in `binding @ sub`.
682682
let PatKind::Binding { name, mode, ty, subpattern: Some(box ref sub), .. } = pat.kind else {
683683
return;
@@ -772,7 +772,7 @@ fn check_borrow_conflicts_in_at_patterns<'tcx>(cx: &MatchVisitor<'_, '_, 'tcx>,
772772
}
773773

774774
fn check_for_bindings_named_same_as_variants(
775-
cx: &MatchVisitor<'_, '_, '_>,
775+
cx: &MatchVisitor<'_, '_>,
776776
pat: &Pat<'_>,
777777
rf: RefutableFlag,
778778
) {

‎compiler/rustc_pattern_analysis/src/constructor.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -861,12 +861,9 @@ impl<Cx: TypeCx> ConstructorSet<Cx> {
861861
#[instrument(level = "debug", skip(self, pcx, ctors), ret)]
862862
pub(crate) fn split<'a>(
863863
&self,
864-
pcx: &PlaceCtxt<'_, '_, Cx>,
864+
pcx: &PlaceCtxt<'a, '_, Cx>,
865865
ctors: impl Iterator<Item = &'a Constructor<Cx>> + Clone,
866-
) -> SplitConstructorSet<Cx>
867-
where
868-
Cx: 'a,
869-
{
866+
) -> SplitConstructorSet<Cx> {
870867
let mut present: SmallVec<[_; 1]> = SmallVec::new();
871868
// Empty constructors found missing.
872869
let mut missing_empty = Vec::new();

‎compiler/rustc_pattern_analysis/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub struct MatchCtxt<'a, 'p, Cx: TypeCx> {
9191
/// The context for type information.
9292
pub tycx: &'a Cx,
9393
/// An arena to store the wildcards we produce during analysis.
94-
pub wildcard_arena: &'a TypedArena<DeconstructedPat<'p, Cx>>,
94+
pub wildcard_arena: &'p TypedArena<DeconstructedPat<'p, Cx>>,
9595
}
9696

9797
/// The arm of a match expression.

‎compiler/rustc_pattern_analysis/src/lints.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ use crate::TypeCx;
2828
///
2929
/// This is not used in the main algorithm; only in lints.
3030
#[derive(Debug)]
31-
pub(crate) struct PatternColumn<'a, 'p, 'tcx> {
32-
patterns: Vec<&'a DeconstructedPat<'p, 'tcx>>,
31+
pub(crate) struct PatternColumn<'p, 'tcx> {
32+
patterns: Vec<&'p DeconstructedPat<'p, 'tcx>>,
3333
}
3434

35-
impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
35+
impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
3636
pub(crate) fn new(arms: &[MatchArm<'p, 'tcx>]) -> Self {
3737
let mut patterns = Vec::with_capacity(arms.len());
3838
for arm in arms {
@@ -48,7 +48,7 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
4848
fn is_empty(&self) -> bool {
4949
self.patterns.is_empty()
5050
}
51-
fn head_ty(&self, cx: MatchCtxt<'a, 'p, 'tcx>) -> Option<Ty<'tcx>> {
51+
fn head_ty(&self, cx: MatchCtxt<'_, 'p, 'tcx>) -> Option<Ty<'tcx>> {
5252
if self.patterns.len() == 0 {
5353
return None;
5454
}
@@ -64,7 +64,7 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
6464
pcx.ctors_for_ty().split(pcx, column_ctors)
6565
}
6666

67-
fn iter<'b>(&'b self) -> impl Iterator<Item = &'a DeconstructedPat<'p, 'tcx>> + Captures<'b> {
67+
fn iter(&self) -> impl Iterator<Item = &'p DeconstructedPat<'p, 'tcx>> + Captures<'_> {
6868
self.patterns.iter().copied()
6969
}
7070

@@ -75,9 +75,9 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
7575
/// which may change the lengths.
7676
fn specialize(
7777
&self,
78-
pcx: &PlaceCtxt<'a, 'p, 'tcx>,
78+
pcx: &PlaceCtxt<'_, 'p, 'tcx>,
7979
ctor: &Constructor<'p, 'tcx>,
80-
) -> Vec<PatternColumn<'a, 'p, 'tcx>> {
80+
) -> Vec<PatternColumn<'p, 'tcx>> {
8181
let arity = ctor.arity(pcx);
8282
if arity == 0 {
8383
return Vec::new();
@@ -115,7 +115,7 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
115115
#[instrument(level = "debug", skip(cx), ret)]
116116
fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
117117
cx: MatchCtxt<'a, 'p, 'tcx>,
118-
column: &PatternColumn<'a, 'p, 'tcx>,
118+
column: &PatternColumn<'p, 'tcx>,
119119
) -> Vec<WitnessPat<'p, 'tcx>> {
120120
let Some(ty) = column.head_ty(cx) else {
121121
return Vec::new();
@@ -163,7 +163,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
163163
pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
164164
cx: MatchCtxt<'a, 'p, 'tcx>,
165165
arms: &[MatchArm<'p, 'tcx>],
166-
pat_column: &PatternColumn<'a, 'p, 'tcx>,
166+
pat_column: &PatternColumn<'p, 'tcx>,
167167
scrut_ty: Ty<'tcx>,
168168
) {
169169
let rcx: &RustcMatchCheckCtxt<'_, '_> = cx.tycx;
@@ -216,7 +216,7 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
216216
#[instrument(level = "debug", skip(cx))]
217217
pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'tcx>(
218218
cx: MatchCtxt<'a, 'p, 'tcx>,
219-
column: &PatternColumn<'a, 'p, 'tcx>,
219+
column: &PatternColumn<'p, 'tcx>,
220220
) {
221221
let Some(ty) = column.head_ty(cx) else {
222222
return;

‎compiler/rustc_pattern_analysis/src/pat.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,17 @@ impl<'p, Cx: TypeCx> DeconstructedPat<'p, Cx> {
7171
self.data.as_ref()
7272
}
7373

74-
pub fn iter_fields<'a>(
75-
&'a self,
76-
) -> impl Iterator<Item = &'p DeconstructedPat<'p, Cx>> + Captures<'a> {
74+
pub fn iter_fields(&self) -> impl Iterator<Item = &'p DeconstructedPat<'p, Cx>> + Captures<'_> {
7775
self.fields.iter()
7876
}
7977

8078
/// Specialize this pattern with a constructor.
8179
/// `other_ctor` can be different from `self.ctor`, but must be covered by it.
82-
pub(crate) fn specialize<'a>(
80+
pub(crate) fn specialize(
8381
&self,
84-
pcx: &PlaceCtxt<'a, 'p, Cx>,
82+
pcx: &PlaceCtxt<'_, 'p, Cx>,
8583
other_ctor: &Constructor<Cx>,
86-
) -> SmallVec<[&'a DeconstructedPat<'p, Cx>; 2]> {
84+
) -> SmallVec<[&'p DeconstructedPat<'p, Cx>; 2]> {
8785
let wildcard_sub_tys = || {
8886
let tys = pcx.ctor_sub_tys(other_ctor);
8987
tys.iter()
@@ -196,7 +194,7 @@ impl<Cx: TypeCx> WitnessPat<Cx> {
196194
self.ty
197195
}
198196

199-
pub fn iter_fields<'a>(&'a self) -> impl Iterator<Item = &'a WitnessPat<Cx>> {
197+
pub fn iter_fields(&self) -> impl Iterator<Item = &WitnessPat<Cx>> {
200198
self.fields.iter()
201199
}
202200
}

‎compiler/rustc_pattern_analysis/src/rustc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
128128
// In the cases of either a `#[non_exhaustive]` field list or a non-public field, we hide
129129
// uninhabited fields in order not to reveal the uninhabitedness of the whole variant.
130130
// This lists the fields we keep along with their types.
131-
pub(crate) fn list_variant_nonhidden_fields<'a>(
132-
&'a self,
131+
pub(crate) fn list_variant_nonhidden_fields(
132+
&self,
133133
ty: Ty<'tcx>,
134-
variant: &'a VariantDef,
135-
) -> impl Iterator<Item = (FieldIdx, Ty<'tcx>)> + Captures<'p> + Captures<'a> {
134+
variant: &'tcx VariantDef,
135+
) -> impl Iterator<Item = (FieldIdx, Ty<'tcx>)> + Captures<'p> + Captures<'_> {
136136
let cx = self;
137137
let ty::Adt(adt, args) = ty.kind() else { bug!() };
138138
// Whether we must not match the fields of this variant exhaustively.
@@ -399,7 +399,7 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
399399

400400
/// Note: the input patterns must have been lowered through
401401
/// `rustc_mir_build::thir::pattern::check_match::MatchVisitor::lower_pattern`.
402-
pub fn lower_pat(&self, pat: &Pat<'tcx>) -> DeconstructedPat<'p, 'tcx> {
402+
pub fn lower_pat(&self, pat: &'p Pat<'tcx>) -> DeconstructedPat<'p, 'tcx> {
403403
let singleton = |pat| std::slice::from_ref(self.pattern_arena.alloc(pat));
404404
let cx = self;
405405
let ctor;

‎compiler/rustc_pattern_analysis/src/usefulness.rs

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -821,22 +821,21 @@ impl fmt::Display for ValidityConstraint {
821821

822822
/// Represents a pattern-tuple under investigation.
823823
// The three lifetimes are:
824-
// - 'a allocated by us
825824
// - 'p coming from the input
826825
// - Cx global compilation context
827826
#[derive(derivative::Derivative)]
828827
#[derivative(Clone(bound = ""))]
829-
struct PatStack<'a, 'p, Cx: TypeCx> {
828+
struct PatStack<'p, Cx: TypeCx> {
830829
// Rows of len 1 are very common, which is why `SmallVec[_; 2]` works well.
831-
pats: SmallVec<[&'a DeconstructedPat<'p, Cx>; 2]>,
830+
pats: SmallVec<[&'p DeconstructedPat<'p, Cx>; 2]>,
832831
/// Sometimes we know that as far as this row is concerned, the current case is already handled
833832
/// by a different, more general, case. When the case is irrelevant for all rows this allows us
834833
/// to skip a case entirely. This is purely an optimization. See at the top for details.
835834
relevant: bool,
836835
}
837836

838-
impl<'a, 'p, Cx: TypeCx> PatStack<'a, 'p, Cx> {
839-
fn from_pattern(pat: &'a DeconstructedPat<'p, Cx>) -> Self {
837+
impl<'p, Cx: TypeCx> PatStack<'p, Cx> {
838+
fn from_pattern(pat: &'p DeconstructedPat<'p, Cx>) -> Self {
840839
PatStack { pats: smallvec![pat], relevant: true }
841840
}
842841

@@ -848,17 +847,17 @@ impl<'a, 'p, Cx: TypeCx> PatStack<'a, 'p, Cx> {
848847
self.pats.len()
849848
}
850849

851-
fn head(&self) -> &'a DeconstructedPat<'p, Cx> {
850+
fn head(&self) -> &'p DeconstructedPat<'p, Cx> {
852851
self.pats[0]
853852
}
854853

855-
fn iter<'b>(&'b self) -> impl Iterator<Item = &'a DeconstructedPat<'p, Cx>> + Captures<'b> {
854+
fn iter(&self) -> impl Iterator<Item = &'p DeconstructedPat<'p, Cx>> + Captures<'_> {
856855
self.pats.iter().copied()
857856
}
858857

859858
// Recursively expand the first or-pattern into its subpatterns. Only useful if the pattern is
860859
// an or-pattern. Panics if `self` is empty.
861-
fn expand_or_pat<'b>(&'b self) -> impl Iterator<Item = PatStack<'a, 'p, Cx>> + Captures<'b> {
860+
fn expand_or_pat(&self) -> impl Iterator<Item = PatStack<'p, Cx>> + Captures<'_> {
862861
self.head().flatten_or_pat().into_iter().map(move |pat| {
863862
let mut new = self.clone();
864863
new.pats[0] = pat;
@@ -870,10 +869,10 @@ impl<'a, 'p, Cx: TypeCx> PatStack<'a, 'p, Cx> {
870869
/// Only call if `ctor.is_covered_by(self.head().ctor())` is true.
871870
fn pop_head_constructor(
872871
&self,
873-
pcx: &PlaceCtxt<'a, 'p, Cx>,
872+
pcx: &PlaceCtxt<'_, 'p, Cx>,
874873
ctor: &Constructor<Cx>,
875874
ctor_is_relevant: bool,
876-
) -> PatStack<'a, 'p, Cx> {
875+
) -> PatStack<'p, Cx> {
877876
// We pop the head pattern and push the new fields extracted from the arguments of
878877
// `self.head()`.
879878
let mut new_pats = self.head().specialize(pcx, ctor);
@@ -886,7 +885,7 @@ impl<'a, 'p, Cx: TypeCx> PatStack<'a, 'p, Cx> {
886885
}
887886
}
888887

889-
impl<'a, 'p, Cx: TypeCx> fmt::Debug for PatStack<'a, 'p, Cx> {
888+
impl<'p, Cx: TypeCx> fmt::Debug for PatStack<'p, Cx> {
890889
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
891890
// We pretty-print similarly to the `Debug` impl of `Matrix`.
892891
write!(f, "+")?;
@@ -899,9 +898,9 @@ impl<'a, 'p, Cx: TypeCx> fmt::Debug for PatStack<'a, 'p, Cx> {
899898

900899
/// A row of the matrix.
901900
#[derive(Clone)]
902-
struct MatrixRow<'a, 'p, Cx: TypeCx> {
901+
struct MatrixRow<'p, Cx: TypeCx> {
903902
// The patterns in the row.
904-
pats: PatStack<'a, 'p, Cx>,
903+
pats: PatStack<'p, Cx>,
905904
/// Whether the original arm had a guard. This is inherited when specializing.
906905
is_under_guard: bool,
907906
/// When we specialize, we remember which row of the original matrix produced a given row of the
@@ -914,7 +913,7 @@ struct MatrixRow<'a, 'p, Cx: TypeCx> {
914913
useful: bool,
915914
}
916915

917-
impl<'a, 'p, Cx: TypeCx> MatrixRow<'a, 'p, Cx> {
916+
impl<'p, Cx: TypeCx> MatrixRow<'p, Cx> {
918917
fn is_empty(&self) -> bool {
919918
self.pats.is_empty()
920919
}
@@ -923,17 +922,17 @@ impl<'a, 'p, Cx: TypeCx> MatrixRow<'a, 'p, Cx> {
923922
self.pats.len()
924923
}
925924

926-
fn head(&self) -> &'a DeconstructedPat<'p, Cx> {
925+
fn head(&self) -> &'p DeconstructedPat<'p, Cx> {
927926
self.pats.head()
928927
}
929928

930-
fn iter<'b>(&'b self) -> impl Iterator<Item = &'a DeconstructedPat<'p, Cx>> + Captures<'b> {
929+
fn iter(&self) -> impl Iterator<Item = &'p DeconstructedPat<'p, Cx>> + Captures<'_> {
931930
self.pats.iter()
932931
}
933932

934933
// Recursively expand the first or-pattern into its subpatterns. Only useful if the pattern is
935934
// an or-pattern. Panics if `self` is empty.
936-
fn expand_or_pat<'b>(&'b self) -> impl Iterator<Item = MatrixRow<'a, 'p, Cx>> + Captures<'b> {
935+
fn expand_or_pat(&self) -> impl Iterator<Item = MatrixRow<'p, Cx>> + Captures<'_> {
937936
self.pats.expand_or_pat().map(|patstack| MatrixRow {
938937
pats: patstack,
939938
parent_row: self.parent_row,
@@ -946,11 +945,11 @@ impl<'a, 'p, Cx: TypeCx> MatrixRow<'a, 'p, Cx> {
946945
/// Only call if `ctor.is_covered_by(self.head().ctor())` is true.
947946
fn pop_head_constructor(
948947
&self,
949-
pcx: &PlaceCtxt<'a, 'p, Cx>,
948+
pcx: &PlaceCtxt<'_, 'p, Cx>,
950949
ctor: &Constructor<Cx>,
951950
ctor_is_relevant: bool,
952951
parent_row: usize,
953-
) -> MatrixRow<'a, 'p, Cx> {
952+
) -> MatrixRow<'p, Cx> {
954953
MatrixRow {
955954
pats: self.pats.pop_head_constructor(pcx, ctor, ctor_is_relevant),
956955
parent_row,
@@ -960,7 +959,7 @@ impl<'a, 'p, Cx: TypeCx> MatrixRow<'a, 'p, Cx> {
960959
}
961960
}
962961

963-
impl<'a, 'p, Cx: TypeCx> fmt::Debug for MatrixRow<'a, 'p, Cx> {
962+
impl<'p, Cx: TypeCx> fmt::Debug for MatrixRow<'p, Cx> {
964963
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
965964
self.pats.fmt(f)
966965
}
@@ -977,22 +976,22 @@ impl<'a, 'p, Cx: TypeCx> fmt::Debug for MatrixRow<'a, 'p, Cx> {
977976
/// specializing `(,)` and `Some` on a pattern of type `(Option<u32>, bool)`, the first column of
978977
/// the matrix will correspond to `scrutinee.0.Some.0` and the second column to `scrutinee.1`.
979978
#[derive(Clone)]
980-
struct Matrix<'a, 'p, Cx: TypeCx> {
979+
struct Matrix<'p, Cx: TypeCx> {
981980
/// Vector of rows. The rows must form a rectangular 2D array. Moreover, all the patterns of
982981
/// each column must have the same type. Each column corresponds to a place within the
983982
/// scrutinee.
984-
rows: Vec<MatrixRow<'a, 'p, Cx>>,
983+
rows: Vec<MatrixRow<'p, Cx>>,
985984
/// Stores an extra fictitious row full of wildcards. Mostly used to keep track of the type of
986985
/// each column. This must obey the same invariants as the real rows.
987-
wildcard_row: PatStack<'a, 'p, Cx>,
986+
wildcard_row: PatStack<'p, Cx>,
988987
/// Track for each column/place whether it contains a known valid value.
989988
place_validity: SmallVec<[ValidityConstraint; 2]>,
990989
}
991990

992-
impl<'a, 'p, Cx: TypeCx> Matrix<'a, 'p, Cx> {
991+
impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
993992
/// Pushes a new row to the matrix. If the row starts with an or-pattern, this recursively
994993
/// expands it. Internal method, prefer [`Matrix::new`].
995-
fn expand_and_push(&mut self, row: MatrixRow<'a, 'p, Cx>) {
994+
fn expand_and_push(&mut self, row: MatrixRow<'p, Cx>) {
996995
if !row.is_empty() && row.head().is_or_pat() {
997996
// Expand nested or-patterns.
998997
for new_row in row.expand_or_pat() {
@@ -1005,8 +1004,8 @@ impl<'a, 'p, Cx: TypeCx> Matrix<'a, 'p, Cx> {
10051004

10061005
/// Build a new matrix from an iterator of `MatchArm`s.
10071006
fn new(
1008-
wildcard_arena: &'a TypedArena<DeconstructedPat<'p, Cx>>,
1009-
arms: &'a [MatchArm<'p, Cx>],
1007+
wildcard_arena: &'p TypedArena<DeconstructedPat<'p, Cx>>,
1008+
arms: &[MatchArm<'p, Cx>],
10101009
scrut_ty: Cx::Ty,
10111010
scrut_validity: ValidityConstraint,
10121011
) -> Self {
@@ -1029,7 +1028,7 @@ impl<'a, 'p, Cx: TypeCx> Matrix<'a, 'p, Cx> {
10291028
matrix
10301029
}
10311030

1032-
fn head_ty(&self, mcx: MatchCtxt<'a, 'p, Cx>) -> Option<Cx::Ty> {
1031+
fn head_ty(&self, mcx: MatchCtxt<'_, 'p, Cx>) -> Option<Cx::Ty> {
10331032
if self.column_count() == 0 {
10341033
return None;
10351034
}
@@ -1042,33 +1041,31 @@ impl<'a, 'p, Cx: TypeCx> Matrix<'a, 'p, Cx> {
10421041
self.wildcard_row.len()
10431042
}
10441043

1045-
fn rows<'b>(
1046-
&'b self,
1047-
) -> impl Iterator<Item = &'b MatrixRow<'a, 'p, Cx>> + Clone + DoubleEndedIterator + ExactSizeIterator
1044+
fn rows(
1045+
&self,
1046+
) -> impl Iterator<Item = &MatrixRow<'p, Cx>> + Clone + DoubleEndedIterator + ExactSizeIterator
10481047
{
10491048
self.rows.iter()
10501049
}
1051-
fn rows_mut<'b>(
1052-
&'b mut self,
1053-
) -> impl Iterator<Item = &'b mut MatrixRow<'a, 'p, Cx>> + DoubleEndedIterator + ExactSizeIterator
1050+
fn rows_mut(
1051+
&mut self,
1052+
) -> impl Iterator<Item = &mut MatrixRow<'p, Cx>> + DoubleEndedIterator + ExactSizeIterator
10541053
{
10551054
self.rows.iter_mut()
10561055
}
10571056

10581057
/// Iterate over the first pattern of each row.
1059-
fn heads<'b>(
1060-
&'b self,
1061-
) -> impl Iterator<Item = &'b DeconstructedPat<'p, Cx>> + Clone + Captures<'a> {
1058+
fn heads(&self) -> impl Iterator<Item = &'p DeconstructedPat<'p, Cx>> + Clone + Captures<'_> {
10621059
self.rows().map(|r| r.head())
10631060
}
10641061

10651062
/// This computes `specialize(ctor, self)`. See top of the file for explanations.
10661063
fn specialize_constructor(
10671064
&self,
1068-
pcx: &PlaceCtxt<'a, 'p, Cx>,
1065+
pcx: &PlaceCtxt<'_, 'p, Cx>,
10691066
ctor: &Constructor<Cx>,
10701067
ctor_is_relevant: bool,
1071-
) -> Matrix<'a, 'p, Cx> {
1068+
) -> Matrix<'p, Cx> {
10721069
let wildcard_row = self.wildcard_row.pop_head_constructor(pcx, ctor, ctor_is_relevant);
10731070
let new_validity = self.place_validity[0].specialize(ctor);
10741071
let new_place_validity = std::iter::repeat(new_validity)
@@ -1097,7 +1094,7 @@ impl<'a, 'p, Cx: TypeCx> Matrix<'a, 'p, Cx> {
10971094
/// + _ + [_, _, tail @ ..] +
10981095
/// | ✓ | ? | // column validity
10991096
/// ```
1100-
impl<'a, 'p, Cx: TypeCx> fmt::Debug for Matrix<'a, 'p, Cx> {
1097+
impl<'p, Cx: TypeCx> fmt::Debug for Matrix<'p, Cx> {
11011098
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11021099
write!(f, "\n")?;
11031100

@@ -1336,7 +1333,7 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
13361333
#[instrument(level = "debug", skip(mcx, is_top_level), ret)]
13371334
fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
13381335
mcx: MatchCtxt<'a, 'p, Cx>,
1339-
matrix: &mut Matrix<'a, 'p, Cx>,
1336+
matrix: &mut Matrix<'p, Cx>,
13401337
is_top_level: bool,
13411338
) -> WitnessMatrix<Cx> {
13421339
debug_assert!(matrix.rows().all(|r| r.len() == matrix.column_count()));

‎compiler/rustc_ty_utils/src/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,15 @@ impl<'a, 'tcx> visit::Visitor<'a, 'tcx> for IsThirPolymorphic<'a, 'tcx> {
379379
}
380380

381381
#[instrument(skip(self), level = "debug")]
382-
fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
382+
fn visit_expr(&mut self, expr: &'a thir::Expr<'tcx>) {
383383
self.is_poly |= self.expr_is_poly(expr);
384384
if !self.is_poly {
385385
visit::walk_expr(self, expr)
386386
}
387387
}
388388

389389
#[instrument(skip(self), level = "debug")]
390-
fn visit_pat(&mut self, pat: &thir::Pat<'tcx>) {
390+
fn visit_pat(&mut self, pat: &'a thir::Pat<'tcx>) {
391391
self.is_poly |= self.pat_is_poly(pat);
392392
if !self.is_poly {
393393
visit::walk_pat(self, pat);

0 commit comments

Comments
 (0)
Please sign in to comment.