Rollup merge of #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 0292eb9bb9b897f5c0926c6a8530877f67e7cc9b, and then simplified more lifetimes in `MatchVisitor`, which should make #119233 a very simple PR! r? Nadrieril
This commit is contained in:
commit
e1be642b41
10 changed files with 111 additions and 104 deletions
|
@ -28,11 +28,11 @@ use crate::TypeCx;
|
|||
///
|
||||
/// This is not used in the main algorithm; only in lints.
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct PatternColumn<'a, 'p, 'tcx> {
|
||||
patterns: Vec<&'a DeconstructedPat<'p, 'tcx>>,
|
||||
pub(crate) struct PatternColumn<'p, 'tcx> {
|
||||
patterns: Vec<&'p DeconstructedPat<'p, 'tcx>>,
|
||||
}
|
||||
|
||||
impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
|
||||
impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
|
||||
pub(crate) fn new(arms: &[MatchArm<'p, 'tcx>]) -> Self {
|
||||
let mut patterns = Vec::with_capacity(arms.len());
|
||||
for arm in arms {
|
||||
|
@ -48,7 +48,7 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
|
|||
fn is_empty(&self) -> bool {
|
||||
self.patterns.is_empty()
|
||||
}
|
||||
fn head_ty(&self, cx: MatchCtxt<'a, 'p, 'tcx>) -> Option<Ty<'tcx>> {
|
||||
fn head_ty(&self, cx: MatchCtxt<'_, 'p, 'tcx>) -> Option<Ty<'tcx>> {
|
||||
if self.patterns.len() == 0 {
|
||||
return None;
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
|
|||
pcx.ctors_for_ty().split(pcx, column_ctors)
|
||||
}
|
||||
|
||||
fn iter<'b>(&'b self) -> impl Iterator<Item = &'a DeconstructedPat<'p, 'tcx>> + Captures<'b> {
|
||||
fn iter(&self) -> impl Iterator<Item = &'p DeconstructedPat<'p, 'tcx>> + Captures<'_> {
|
||||
self.patterns.iter().copied()
|
||||
}
|
||||
|
||||
|
@ -75,9 +75,9 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
|
|||
/// which may change the lengths.
|
||||
fn specialize(
|
||||
&self,
|
||||
pcx: &PlaceCtxt<'a, 'p, 'tcx>,
|
||||
pcx: &PlaceCtxt<'_, 'p, 'tcx>,
|
||||
ctor: &Constructor<'p, 'tcx>,
|
||||
) -> Vec<PatternColumn<'a, 'p, 'tcx>> {
|
||||
) -> Vec<PatternColumn<'p, 'tcx>> {
|
||||
let arity = ctor.arity(pcx);
|
||||
if arity == 0 {
|
||||
return Vec::new();
|
||||
|
@ -115,7 +115,7 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
|
|||
#[instrument(level = "debug", skip(cx), ret)]
|
||||
fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
|
||||
cx: MatchCtxt<'a, 'p, 'tcx>,
|
||||
column: &PatternColumn<'a, 'p, 'tcx>,
|
||||
column: &PatternColumn<'p, 'tcx>,
|
||||
) -> Vec<WitnessPat<'p, 'tcx>> {
|
||||
let Some(ty) = column.head_ty(cx) else {
|
||||
return Vec::new();
|
||||
|
@ -163,7 +163,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
|
|||
pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
|
||||
cx: MatchCtxt<'a, 'p, 'tcx>,
|
||||
arms: &[MatchArm<'p, 'tcx>],
|
||||
pat_column: &PatternColumn<'a, 'p, 'tcx>,
|
||||
pat_column: &PatternColumn<'p, 'tcx>,
|
||||
scrut_ty: Ty<'tcx>,
|
||||
) {
|
||||
let rcx: &RustcMatchCheckCtxt<'_, '_> = cx.tycx;
|
||||
|
@ -216,7 +216,7 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
|
|||
#[instrument(level = "debug", skip(cx))]
|
||||
pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'tcx>(
|
||||
cx: MatchCtxt<'a, 'p, 'tcx>,
|
||||
column: &PatternColumn<'a, 'p, 'tcx>,
|
||||
column: &PatternColumn<'p, 'tcx>,
|
||||
) {
|
||||
let Some(ty) = column.head_ty(cx) else {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue