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 8ba3329

Browse files
committedDec 22, 2023
Add 'thir lifetime to RustMatchCheckCtxt
1 parent b0b924d commit 8ba3329

File tree

6 files changed

+96
-81
lines changed

6 files changed

+96
-81
lines changed
 

‎compiler/rustc_mir_build/src/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,14 @@ pub enum UnusedUnsafeEnclosing {
453453
},
454454
}
455455

456-
pub(crate) struct NonExhaustivePatternsTypeNotEmpty<'p, 'tcx, 'm> {
457-
pub cx: &'m RustcMatchCheckCtxt<'p, 'tcx>,
456+
pub(crate) struct NonExhaustivePatternsTypeNotEmpty<'p, 'thir, 'tcx, 'm> {
457+
pub cx: &'m RustcMatchCheckCtxt<'p, 'thir, 'tcx>,
458458
pub expr_span: Span,
459459
pub span: Span,
460460
pub ty: Ty<'tcx>,
461461
}
462462

463-
impl<'a> IntoDiagnostic<'a> for NonExhaustivePatternsTypeNotEmpty<'_, '_, '_> {
463+
impl<'a> IntoDiagnostic<'a> for NonExhaustivePatternsTypeNotEmpty<'_, '_, '_, '_> {
464464
fn into_diagnostic(
465465
self,
466466
dcx: &'a DiagCtxt,

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

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct MatchVisitor<'thir, 'p, 'tcx> {
8686
thir: &'thir Thir<'tcx>,
8787
lint_level: HirId,
8888
let_source: LetSource,
89-
pattern_arena: &'p TypedArena<DeconstructedPat<'p, 'tcx>>,
89+
pattern_arena: &'p TypedArena<DeconstructedPat<'p, 'thir, 'tcx>>,
9090
dropless_arena: &'p DroplessArena,
9191
/// Tracks if we encountered an error while checking this body. That the first function to
9292
/// report it stores it here. Some functions return `Result` to allow callers to short-circuit
@@ -279,9 +279,9 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
279279

280280
fn lower_pattern(
281281
&mut self,
282-
cx: &MatchCheckCtxt<'p, 'tcx>,
282+
cx: &MatchCheckCtxt<'p, 'thir, 'tcx>,
283283
pat: &'thir Pat<'tcx>,
284-
) -> Result<&'p DeconstructedPat<'p, 'tcx>, ErrorGuaranteed> {
284+
) -> Result<&'p DeconstructedPat<'p, 'thir, 'tcx>, ErrorGuaranteed> {
285285
if let Err(err) = pat.pat_error_reported() {
286286
self.error = Err(err);
287287
Err(err)
@@ -374,7 +374,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
374374
whole_match_span: Option<Span>,
375375
scrutinee: Option<&Expr<'tcx>>,
376376
scrut_span: Span,
377-
) -> MatchCheckCtxt<'p, 'tcx> {
377+
) -> MatchCheckCtxt<'p, 'thir, 'tcx> {
378378
let refutable = match refutability {
379379
Irrefutable => false,
380380
Refutable => true,
@@ -554,7 +554,8 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
554554
pat: &'thir Pat<'tcx>,
555555
refutability: RefutableFlag,
556556
scrut: Option<&Expr<'tcx>>,
557-
) -> Result<(MatchCheckCtxt<'p, 'tcx>, UsefulnessReport<'p, 'tcx>), ErrorGuaranteed> {
557+
) -> Result<(MatchCheckCtxt<'p, 'thir, 'tcx>, UsefulnessReport<'p, 'thir, 'tcx>), ErrorGuaranteed>
558+
{
558559
let cx = self.new_cx(refutability, None, scrut, pat.span);
559560
let pat = self.lower_pattern(&cx, pat)?;
560561
let arms = [MatchArm { pat, arm_data: self.lint_level, has_guard: false }];
@@ -840,9 +841,9 @@ fn report_irrefutable_let_patterns(
840841
}
841842

842843
/// Report unreachable arms, if any.
843-
fn report_arm_reachability<'p, 'tcx>(
844-
cx: &MatchCheckCtxt<'p, 'tcx>,
845-
report: &UsefulnessReport<'p, 'tcx>,
844+
fn report_arm_reachability<'p, 'thir, 'tcx>(
845+
cx: &MatchCheckCtxt<'p, 'thir, 'tcx>,
846+
report: &UsefulnessReport<'p, 'thir, 'tcx>,
846847
) {
847848
let report_unreachable_pattern = |span, hir_id, catchall: Option<Span>| {
848849
cx.tcx.emit_spanned_lint(
@@ -880,7 +881,7 @@ fn report_arm_reachability<'p, 'tcx>(
880881
}
881882

882883
/// Checks for common cases of "catchall" patterns that may not be intended as such.
883-
fn pat_is_catchall(pat: &DeconstructedPat<'_, '_>) -> bool {
884+
fn pat_is_catchall(pat: &DeconstructedPat<'_, '_, '_>) -> bool {
884885
match pat.ctor() {
885886
Constructor::Wildcard => true,
886887
Constructor::Struct | Constructor::Ref => pat.iter_fields().all(|pat| pat_is_catchall(pat)),
@@ -889,12 +890,12 @@ fn pat_is_catchall(pat: &DeconstructedPat<'_, '_>) -> bool {
889890
}
890891

891892
/// Report that a match is not exhaustive.
892-
fn report_non_exhaustive_match<'p, 'tcx>(
893-
cx: &MatchCheckCtxt<'p, 'tcx>,
893+
fn report_non_exhaustive_match<'p, 'thir, 'tcx>(
894+
cx: &MatchCheckCtxt<'p, 'thir, 'tcx>,
894895
thir: &Thir<'tcx>,
895896
scrut_ty: Ty<'tcx>,
896897
sp: Span,
897-
witnesses: Vec<WitnessPat<'p, 'tcx>>,
898+
witnesses: Vec<WitnessPat<'p, 'thir, 'tcx>>,
898899
arms: &[ArmId],
899900
expr_span: Span,
900901
) -> ErrorGuaranteed {
@@ -1089,12 +1090,12 @@ fn report_non_exhaustive_match<'p, 'tcx>(
10891090
err.emit()
10901091
}
10911092

1092-
fn joined_uncovered_patterns<'p, 'tcx>(
1093-
cx: &MatchCheckCtxt<'p, 'tcx>,
1094-
witnesses: &[WitnessPat<'p, 'tcx>],
1093+
fn joined_uncovered_patterns<'p, 'thir, 'tcx>(
1094+
cx: &MatchCheckCtxt<'p, 'thir, 'tcx>,
1095+
witnesses: &[WitnessPat<'p, 'thir, 'tcx>],
10951096
) -> String {
10961097
const LIMIT: usize = 3;
1097-
let pat_to_str = |pat: &WitnessPat<'p, 'tcx>| cx.hoist_witness_pat(pat).to_string();
1098+
let pat_to_str = |pat: &WitnessPat<'p, 'thir, 'tcx>| cx.hoist_witness_pat(pat).to_string();
10981099
match witnesses {
10991100
[] => bug!(),
11001101
[witness] => format!("`{}`", cx.hoist_witness_pat(witness)),
@@ -1111,8 +1112,8 @@ fn joined_uncovered_patterns<'p, 'tcx>(
11111112
}
11121113

11131114
fn collect_non_exhaustive_tys<'tcx>(
1114-
cx: &MatchCheckCtxt<'_, 'tcx>,
1115-
pat: &WitnessPat<'_, 'tcx>,
1115+
cx: &MatchCheckCtxt<'_, '_, 'tcx>,
1116+
pat: &WitnessPat<'_, '_, 'tcx>,
11161117
non_exhaustive_tys: &mut FxIndexSet<Ty<'tcx>>,
11171118
) {
11181119
if matches!(pat.ctor(), Constructor::NonExhaustive) {
@@ -1131,7 +1132,7 @@ fn collect_non_exhaustive_tys<'tcx>(
11311132
fn report_adt_defined_here<'tcx>(
11321133
tcx: TyCtxt<'tcx>,
11331134
ty: Ty<'tcx>,
1134-
witnesses: &[WitnessPat<'_, 'tcx>],
1135+
witnesses: &[WitnessPat<'_, '_, 'tcx>],
11351136
point_at_non_local_ty: bool,
11361137
) -> Option<AdtDefinedHere<'tcx>> {
11371138
let ty = ty.peel_refs();
@@ -1153,10 +1154,10 @@ fn report_adt_defined_here<'tcx>(
11531154
Some(AdtDefinedHere { adt_def_span, ty, variants })
11541155
}
11551156

1156-
fn maybe_point_at_variant<'a, 'p: 'a, 'tcx: 'p>(
1157+
fn maybe_point_at_variant<'a, 'p: 'a, 'thir: 'p, 'tcx: 'thir>(
11571158
tcx: TyCtxt<'tcx>,
11581159
def: AdtDef<'tcx>,
1159-
patterns: impl Iterator<Item = &'a WitnessPat<'p, 'tcx>>,
1160+
patterns: impl Iterator<Item = &'a WitnessPat<'p, 'thir, 'tcx>>,
11601161
) -> Vec<Span> {
11611162
let mut covered = vec![];
11621163
for pattern in patterns {

‎compiler/rustc_pattern_analysis/src/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ pub struct Uncovered<'tcx> {
1919
}
2020

2121
impl<'tcx> Uncovered<'tcx> {
22-
pub fn new<'p>(
22+
pub fn new<'p, 'thir>(
2323
span: Span,
24-
cx: &RustcMatchCheckCtxt<'p, 'tcx>,
25-
witnesses: Vec<WitnessPat<'p, 'tcx>>,
24+
cx: &RustcMatchCheckCtxt<'p, 'thir, 'tcx>,
25+
witnesses: Vec<WitnessPat<'p, 'thir, 'tcx>>,
2626
) -> Self {
2727
let witness_1 = cx.hoist_witness_pat(witnesses.get(0).unwrap());
2828
Self {

‎compiler/rustc_pattern_analysis/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ impl<'p, Cx: TypeCx> Copy for MatchArm<'p, Cx> {}
109109
/// The entrypoint for this crate. Computes whether a match is exhaustive and which of its arms are
110110
/// useful, and runs some lints.
111111
#[cfg(feature = "rustc")]
112-
pub fn analyze_match<'p, 'tcx>(
113-
tycx: &RustcMatchCheckCtxt<'p, 'tcx>,
114-
arms: &[rustc::MatchArm<'p, 'tcx>],
112+
pub fn analyze_match<'p, 'thir, 'tcx>(
113+
tycx: &RustcMatchCheckCtxt<'p, 'thir, 'tcx>,
114+
arms: &[rustc::MatchArm<'p, 'thir, 'tcx>],
115115
scrut_ty: Ty<'tcx>,
116-
) -> rustc::UsefulnessReport<'p, 'tcx> {
116+
) -> rustc::UsefulnessReport<'p, 'thir, 'tcx> {
117117
// Arena to store the extra wildcards we construct during analysis.
118118
let wildcard_arena = tycx.pattern_arena;
119119
let scrut_validity = ValidityConstraint::from_bool(tycx.known_valid_scrutinee);

‎compiler/rustc_pattern_analysis/src/lints.rs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ 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<'a, 'p, 'thir, 'tcx> {
32+
patterns: Vec<&'a DeconstructedPat<'p, 'thir, 'tcx>>,
3333
}
3434

35-
impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
36-
pub(crate) fn new(arms: &[MatchArm<'p, 'tcx>]) -> Self {
35+
impl<'a, 'p, 'thir, 'tcx> PatternColumn<'a, 'p, 'thir, 'tcx> {
36+
pub(crate) fn new(arms: &[MatchArm<'p, 'thir, 'tcx>]) -> Self {
3737
let mut patterns = Vec::with_capacity(arms.len());
3838
for arm in arms {
3939
if arm.pat.is_or_pat() {
@@ -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<'a, 'p, 'thir, 'tcx>) -> Option<Ty<'tcx>> {
5252
if self.patterns.len() == 0 {
5353
return None;
5454
}
@@ -59,12 +59,17 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
5959
}
6060

6161
/// Do constructor splitting on the constructors of the column.
62-
fn analyze_ctors(&self, pcx: &PlaceCtxt<'_, 'p, 'tcx>) -> SplitConstructorSet<'p, 'tcx> {
62+
fn analyze_ctors(
63+
&self,
64+
pcx: &PlaceCtxt<'_, 'p, 'thir, 'tcx>,
65+
) -> SplitConstructorSet<'p, 'thir, 'tcx> {
6366
let column_ctors = self.patterns.iter().map(|p| p.ctor());
6467
pcx.ctors_for_ty().split(pcx, column_ctors)
6568
}
6669

67-
fn iter<'b>(&'b self) -> impl Iterator<Item = &'a DeconstructedPat<'p, 'tcx>> + Captures<'b> {
70+
fn iter<'b>(
71+
&'b self,
72+
) -> impl Iterator<Item = &'a DeconstructedPat<'p, 'thir, 'tcx>> + Captures<'b> {
6873
self.patterns.iter().copied()
6974
}
7075

@@ -75,9 +80,9 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
7580
/// which may change the lengths.
7681
fn specialize(
7782
&self,
78-
pcx: &PlaceCtxt<'a, 'p, 'tcx>,
79-
ctor: &Constructor<'p, 'tcx>,
80-
) -> Vec<PatternColumn<'a, 'p, 'tcx>> {
83+
pcx: &PlaceCtxt<'a, 'p, 'thir, 'tcx>,
84+
ctor: &Constructor<'p, 'thir, 'tcx>,
85+
) -> Vec<PatternColumn<'a, 'p, 'thir, 'tcx>> {
8186
let arity = ctor.arity(pcx);
8287
if arity == 0 {
8388
return Vec::new();
@@ -113,10 +118,10 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
113118
/// Traverse the patterns to collect any variants of a non_exhaustive enum that fail to be mentioned
114119
/// in a given column.
115120
#[instrument(level = "debug", skip(cx), ret)]
116-
fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
117-
cx: MatchCtxt<'a, 'p, 'tcx>,
118-
column: &PatternColumn<'a, 'p, 'tcx>,
119-
) -> Vec<WitnessPat<'p, 'tcx>> {
121+
fn collect_nonexhaustive_missing_variants<'a, 'p, 'thir, 'tcx>(
122+
cx: MatchCtxt<'a, 'p, 'thir, 'tcx>,
123+
column: &PatternColumn<'a, 'p, 'thir, 'tcx>,
124+
) -> Vec<WitnessPat<'p, 'thir, 'tcx>> {
120125
let Some(ty) = column.head_ty(cx) else {
121126
return Vec::new();
122127
};
@@ -160,13 +165,13 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
160165
witnesses
161166
}
162167

163-
pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
164-
cx: MatchCtxt<'a, 'p, 'tcx>,
165-
arms: &[MatchArm<'p, 'tcx>],
166-
pat_column: &PatternColumn<'a, 'p, 'tcx>,
168+
pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'thir, 'tcx>(
169+
cx: MatchCtxt<'a, 'p, 'thir, 'tcx>,
170+
arms: &[MatchArm<'p, 'thir, 'tcx>],
171+
pat_column: &PatternColumn<'a, 'p, 'thir, 'tcx>,
167172
scrut_ty: Ty<'tcx>,
168173
) {
169-
let rcx: &RustcMatchCheckCtxt<'_, '_> = cx.tycx;
174+
let rcx: &RustcMatchCheckCtxt<'_, '_, '_> = cx.tycx;
170175
if !matches!(
171176
rcx.tcx.lint_level_at_node(NON_EXHAUSTIVE_OMITTED_PATTERNS, rcx.match_lint_level).0,
172177
rustc_session::lint::Level::Allow
@@ -214,15 +219,15 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
214219

215220
/// Traverse the patterns to warn the user about ranges that overlap on their endpoints.
216221
#[instrument(level = "debug", skip(cx))]
217-
pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'tcx>(
218-
cx: MatchCtxt<'a, 'p, 'tcx>,
219-
column: &PatternColumn<'a, 'p, 'tcx>,
222+
pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'thir, 'tcx>(
223+
cx: MatchCtxt<'a, 'p, 'thir, 'tcx>,
224+
column: &PatternColumn<'a, 'p, 'thir, 'tcx>,
220225
) {
221226
let Some(ty) = column.head_ty(cx) else {
222227
return;
223228
};
224229
let pcx = &PlaceCtxt::new_dummy(cx, ty);
225-
let rcx: &RustcMatchCheckCtxt<'_, '_> = cx.tycx;
230+
let rcx: &RustcMatchCheckCtxt<'_, '_, '_> = cx.tycx;
226231

227232
let set = column.analyze_ctors(pcx);
228233

‎compiler/rustc_pattern_analysis/src/rustc.rs

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,28 @@ use crate::TypeCx;
2525
use crate::constructor::Constructor::*;
2626

2727
// Re-export rustc-specific versions of all these types.
28-
pub type Constructor<'p, 'tcx> = crate::constructor::Constructor<RustcMatchCheckCtxt<'p, 'tcx>>;
29-
pub type ConstructorSet<'p, 'tcx> =
30-
crate::constructor::ConstructorSet<RustcMatchCheckCtxt<'p, 'tcx>>;
31-
pub type DeconstructedPat<'p, 'tcx> =
32-
crate::pat::DeconstructedPat<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
33-
pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
34-
pub type MatchCtxt<'a, 'p, 'tcx> = crate::MatchCtxt<'a, 'p, RustcMatchCheckCtxt<'p, 'tcx>>;
35-
pub(crate) type PlaceCtxt<'a, 'p, 'tcx> =
36-
crate::usefulness::PlaceCtxt<'a, 'p, RustcMatchCheckCtxt<'p, 'tcx>>;
37-
pub(crate) type SplitConstructorSet<'p, 'tcx> =
38-
crate::constructor::SplitConstructorSet<RustcMatchCheckCtxt<'p, 'tcx>>;
39-
pub type Usefulness<'p, 'tcx> = crate::usefulness::Usefulness<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
40-
pub type UsefulnessReport<'p, 'tcx> =
41-
crate::usefulness::UsefulnessReport<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
42-
pub type WitnessPat<'p, 'tcx> = crate::pat::WitnessPat<RustcMatchCheckCtxt<'p, 'tcx>>;
28+
pub type Constructor<'p, 'thir, 'tcx> =
29+
crate::constructor::Constructor<RustcMatchCheckCtxt<'p, 'thir, 'tcx>>;
30+
pub type ConstructorSet<'p, 'thir, 'tcx> =
31+
crate::constructor::ConstructorSet<RustcMatchCheckCtxt<'p, 'thir, 'tcx>>;
32+
pub type DeconstructedPat<'p, 'thir, 'tcx> =
33+
crate::pat::DeconstructedPat<'p, RustcMatchCheckCtxt<'p, 'thir, 'tcx>>;
34+
pub type MatchArm<'p, 'thir, 'tcx> = crate::MatchArm<'p, RustcMatchCheckCtxt<'p, 'thir, 'tcx>>;
35+
pub type MatchCtxt<'a, 'p, 'thir, 'tcx> =
36+
crate::MatchCtxt<'a, 'p, RustcMatchCheckCtxt<'p, 'thir, 'tcx>>;
37+
pub(crate) type PlaceCtxt<'a, 'p, 'thir, 'tcx> =
38+
crate::usefulness::PlaceCtxt<'a, 'p, RustcMatchCheckCtxt<'p, 'thir, 'tcx>>;
39+
pub(crate) type SplitConstructorSet<'p, 'thir, 'tcx> =
40+
crate::constructor::SplitConstructorSet<RustcMatchCheckCtxt<'p, 'thir, 'tcx>>;
41+
pub type Usefulness<'p, 'thir, 'tcx> =
42+
crate::usefulness::Usefulness<'p, RustcMatchCheckCtxt<'p, 'thir, 'tcx>>;
43+
pub type UsefulnessReport<'p, 'thir, 'tcx> =
44+
crate::usefulness::UsefulnessReport<'p, RustcMatchCheckCtxt<'p, 'thir, 'tcx>>;
45+
pub type WitnessPat<'p, 'thir, 'tcx> = crate::pat::WitnessPat<RustcMatchCheckCtxt<'p, 'thir, 'tcx>>;
4346

4447
#[derive(Clone)]
45-
pub struct RustcMatchCheckCtxt<'p, 'tcx> {
48+
#[allow(explicit_outlives_requirements)] // FIXME #119228
49+
pub struct RustcMatchCheckCtxt<'p, 'thir, 'tcx: 'thir> {
4650
pub tcx: TyCtxt<'tcx>,
4751
pub typeck_results: &'tcx ty::TypeckResults<'tcx>,
4852
/// The module in which the match occurs. This is necessary for
@@ -52,7 +56,7 @@ pub struct RustcMatchCheckCtxt<'p, 'tcx> {
5256
/// outside its module and should not be matchable with an empty match statement.
5357
pub module: DefId,
5458
pub param_env: ty::ParamEnv<'tcx>,
55-
pub pattern_arena: &'p TypedArena<DeconstructedPat<'p, 'tcx>>,
59+
pub pattern_arena: &'p TypedArena<DeconstructedPat<'p, 'thir, 'tcx>>,
5660
pub dropless_arena: &'p DroplessArena,
5761
/// Lint level at the match.
5862
pub match_lint_level: HirId,
@@ -67,13 +71,13 @@ pub struct RustcMatchCheckCtxt<'p, 'tcx> {
6771
pub known_valid_scrutinee: bool,
6872
}
6973

70-
impl<'p, 'tcx> fmt::Debug for RustcMatchCheckCtxt<'p, 'tcx> {
74+
impl<'p, 'thir, 'tcx> fmt::Debug for RustcMatchCheckCtxt<'p, 'thir, 'tcx> {
7175
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7276
f.debug_struct("RustcMatchCheckCtxt").finish()
7377
}
7478
}
7579

76-
impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
80+
impl<'p, 'thir, 'tcx> RustcMatchCheckCtxt<'p, 'thir, 'tcx> {
7781
pub(crate) fn is_uninhabited(&self, ty: Ty<'tcx>) -> bool {
7882
!ty.is_inhabited_from(self.tcx, self.module, self.param_env)
7983
}
@@ -124,7 +128,8 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
124128
&'a self,
125129
ty: Ty<'tcx>,
126130
variant: &'a VariantDef,
127-
) -> impl Iterator<Item = (FieldIdx, Ty<'tcx>)> + Captures<'p> + Captures<'a> {
131+
) -> impl Iterator<Item = (FieldIdx, Ty<'tcx>)> + Captures<'thir> + Captures<'p> + Captures<'a>
132+
{
128133
let cx = self;
129134
let ty::Adt(adt, args) = ty.kind() else { bug!() };
130135
// Whether we must not match the fields of this variant exhaustively.
@@ -146,7 +151,7 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
146151
}
147152

148153
pub(crate) fn variant_index_for_adt(
149-
ctor: &Constructor<'p, 'tcx>,
154+
ctor: &Constructor<'p, 'thir, 'tcx>,
150155
adt: ty::AdtDef<'tcx>,
151156
) -> VariantIdx {
152157
match *ctor {
@@ -162,7 +167,11 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
162167
/// Returns the types of the fields for a given constructor. The result must have a length of
163168
/// `ctor.arity()`.
164169
#[instrument(level = "trace", skip(self))]
165-
pub(crate) fn ctor_sub_tys(&self, ctor: &Constructor<'p, 'tcx>, ty: Ty<'tcx>) -> &[Ty<'tcx>] {
170+
pub(crate) fn ctor_sub_tys(
171+
&self,
172+
ctor: &Constructor<'p, 'thir, 'tcx>,
173+
ty: Ty<'tcx>,
174+
) -> &[Ty<'tcx>] {
166175
let cx = self;
167176
match ctor {
168177
Struct | Variant(_) | UnionField => match ty.kind() {
@@ -209,7 +218,7 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
209218
}
210219

211220
/// The number of fields for this constructor.
212-
pub(crate) fn ctor_arity(&self, ctor: &Constructor<'p, 'tcx>, ty: Ty<'tcx>) -> usize {
221+
pub(crate) fn ctor_arity(&self, ctor: &Constructor<'p, 'thir, 'tcx>, ty: Ty<'tcx>) -> usize {
213222
match ctor {
214223
Struct | Variant(_) | UnionField => match ty.kind() {
215224
ty::Tuple(fs) => fs.len(),
@@ -246,7 +255,7 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
246255
///
247256
/// See [`crate::constructor`] for considerations of emptiness.
248257
#[instrument(level = "debug", skip(self), ret)]
249-
pub fn ctors_for_ty(&self, ty: Ty<'tcx>) -> ConstructorSet<'p, 'tcx> {
258+
pub fn ctors_for_ty(&self, ty: Ty<'tcx>) -> ConstructorSet<'p, 'thir, 'tcx> {
250259
let cx = self;
251260
let make_uint_range = |start, end| {
252261
IntRange::from_range(
@@ -389,7 +398,7 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
389398

390399
/// Note: the input patterns must have been lowered through
391400
/// `rustc_mir_build::thir::pattern::check_match::MatchVisitor::lower_pattern`.
392-
pub fn lower_pat(&self, pat: &Pat<'tcx>) -> DeconstructedPat<'p, 'tcx> {
401+
pub fn lower_pat(&self, pat: &'thir Pat<'tcx>) -> DeconstructedPat<'p, 'thir, 'tcx> {
393402
let singleton = |pat| std::slice::from_ref(self.pattern_arena.alloc(pat));
394403
let cx = self;
395404
let ctor;
@@ -690,7 +699,7 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
690699
}
691700
/// Convert back to a `thir::Pat` for diagnostic purposes. This panics for patterns that don't
692701
/// appear in diagnostics, like float ranges.
693-
pub fn hoist_witness_pat(&self, pat: &WitnessPat<'p, 'tcx>) -> Pat<'tcx> {
702+
pub fn hoist_witness_pat(&self, pat: &WitnessPat<'p, 'thir, 'tcx>) -> Pat<'tcx> {
694703
let cx = self;
695704
let is_wildcard = |pat: &Pat<'_>| matches!(pat.kind, PatKind::Wild);
696705
let mut subpatterns = pat.iter_fields().map(|p| Box::new(cx.hoist_witness_pat(p)));
@@ -879,7 +888,7 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
879888
}
880889
}
881890

882-
impl<'p, 'tcx> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
891+
impl<'p, 'thir, 'tcx> TypeCx for RustcMatchCheckCtxt<'p, 'thir, 'tcx> {
883892
type Ty = Ty<'tcx>;
884893
type VariantIdx = VariantIdx;
885894
type StrLit = Const<'tcx>;

0 commit comments

Comments
 (0)
Please sign in to comment.