diff options
| author | Michael Goulet <michael@errs.io> | 2025-02-20 18:58:46 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-02-22 22:24:52 +0000 |
| commit | 12e3911d81034864314503b9c2d9fba2773c7904 (patch) | |
| tree | 3c137d293516116a798effc67b2077dbb2025941 /compiler/rustc_pattern_analysis | |
| parent | 46420c96070b4c4bd8242f16d5806b8f26a57016 (diff) | |
| download | rust-12e3911d81034864314503b9c2d9fba2773c7904.tar.gz rust-12e3911d81034864314503b9c2d9fba2773c7904.zip | |
Greatly simplify lifetime captures in edition 2024
Diffstat (limited to 'compiler/rustc_pattern_analysis')
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/lib.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/pat_column.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/rustc.rs | 26 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/usefulness.rs | 25 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/tests/common/mod.rs | 13 |
5 files changed, 35 insertions, 43 deletions
diff --git a/compiler/rustc_pattern_analysis/src/lib.rs b/compiler/rustc_pattern_analysis/src/lib.rs index fec44d5af55..a3400ebb799 100644 --- a/compiler/rustc_pattern_analysis/src/lib.rs +++ b/compiler/rustc_pattern_analysis/src/lib.rs @@ -61,11 +61,11 @@ pub trait PatCx: Sized + fmt::Debug { fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize; /// The types of the fields for this constructor. The result must contain `ctor_arity()` fields. - fn ctor_sub_tys<'a>( - &'a self, - ctor: &'a Constructor<Self>, - ty: &'a Self::Ty, - ) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator + Captures<'a>; + fn ctor_sub_tys( + &self, + ctor: &Constructor<Self>, + ty: &Self::Ty, + ) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator; /// The set of all the constructors for `ty`. /// diff --git a/compiler/rustc_pattern_analysis/src/pat_column.rs b/compiler/rustc_pattern_analysis/src/pat_column.rs index eb4e095c1c6..814eb8afcfc 100644 --- a/compiler/rustc_pattern_analysis/src/pat_column.rs +++ b/compiler/rustc_pattern_analysis/src/pat_column.rs @@ -1,6 +1,6 @@ use crate::constructor::{Constructor, SplitConstructorSet}; use crate::pat::{DeconstructedPat, PatOrWild}; -use crate::{Captures, MatchArm, PatCx}; +use crate::{MatchArm, PatCx}; /// A column of patterns in a match, where a column is the intuitive notion of "subpatterns that /// inspect the same subvalue/place". @@ -41,7 +41,7 @@ impl<'p, Cx: PatCx> PatternColumn<'p, Cx> { pub fn head_ty(&self) -> Option<&Cx::Ty> { self.patterns.first().map(|pat| pat.ty()) } - pub fn iter<'a>(&'a self) -> impl Iterator<Item = &'p DeconstructedPat<Cx>> + Captures<'a> { + pub fn iter(&self) -> impl Iterator<Item = &'p DeconstructedPat<Cx>> { self.patterns.iter().copied() } diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index 0b1e954d64d..88194c737a6 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -25,7 +25,7 @@ use crate::lints::lint_nonexhaustive_missing_variants; use crate::pat_column::PatternColumn; use crate::rustc::print::EnumInfo; use crate::usefulness::{PlaceValidity, compute_match_usefulness}; -use crate::{Captures, PatCx, PrivateUninhabitedField, errors}; +use crate::{PatCx, PrivateUninhabitedField, errors}; mod print; @@ -175,8 +175,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { &self, ty: RevealedTy<'tcx>, variant: &'tcx VariantDef, - ) -> impl Iterator<Item = (&'tcx FieldDef, RevealedTy<'tcx>)> + Captures<'p> + Captures<'_> - { + ) -> impl Iterator<Item = (&'tcx FieldDef, RevealedTy<'tcx>)> { let ty::Adt(_, args) = ty.kind() else { bug!() }; variant.fields.iter().map(move |field| { let ty = field.ty(self.tcx, args); @@ -203,13 +202,11 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { /// Returns the types of the fields for a given constructor. The result must have a length of /// `ctor.arity()`. - pub(crate) fn ctor_sub_tys<'a>( - &'a self, - ctor: &'a Constructor<'p, 'tcx>, + pub(crate) fn ctor_sub_tys( + &self, + ctor: &Constructor<'p, 'tcx>, ty: RevealedTy<'tcx>, - ) -> impl Iterator<Item = (RevealedTy<'tcx>, PrivateUninhabitedField)> - + ExactSizeIterator - + Captures<'a> { + ) -> impl Iterator<Item = (RevealedTy<'tcx>, PrivateUninhabitedField)> + ExactSizeIterator { fn reveal_and_alloc<'a, 'tcx>( cx: &'a RustcPatCtxt<'_, 'tcx>, iter: impl Iterator<Item = Ty<'tcx>>, @@ -936,12 +933,11 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> { fn ctor_arity(&self, ctor: &crate::constructor::Constructor<Self>, ty: &Self::Ty) -> usize { self.ctor_arity(ctor, *ty) } - fn ctor_sub_tys<'a>( - &'a self, - ctor: &'a crate::constructor::Constructor<Self>, - ty: &'a Self::Ty, - ) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator + Captures<'a> - { + fn ctor_sub_tys( + &self, + ctor: &crate::constructor::Constructor<Self>, + ty: &Self::Ty, + ) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator { self.ctor_sub_tys(ctor, *ty) } fn ctors_for_ty( diff --git a/compiler/rustc_pattern_analysis/src/usefulness.rs b/compiler/rustc_pattern_analysis/src/usefulness.rs index 1dff76141da..11ebbea07fa 100644 --- a/compiler/rustc_pattern_analysis/src/usefulness.rs +++ b/compiler/rustc_pattern_analysis/src/usefulness.rs @@ -719,7 +719,7 @@ use tracing::{debug, instrument}; use self::PlaceValidity::*; use crate::constructor::{Constructor, ConstructorSet, IntRange}; use crate::pat::{DeconstructedPat, PatId, PatOrWild, WitnessPat}; -use crate::{Captures, MatchArm, PatCx, PrivateUninhabitedField}; +use crate::{MatchArm, PatCx, PrivateUninhabitedField}; #[cfg(not(feature = "rustc"))] pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R { f() @@ -902,11 +902,11 @@ struct PlaceInfo<Cx: PatCx> { impl<Cx: PatCx> PlaceInfo<Cx> { /// Given a constructor for the current place, we return one `PlaceInfo` for each field of the /// constructor. - fn specialize<'a>( - &'a self, - cx: &'a Cx, - ctor: &'a Constructor<Cx>, - ) -> impl Iterator<Item = Self> + ExactSizeIterator + Captures<'a> { + fn specialize( + &self, + cx: &Cx, + ctor: &Constructor<Cx>, + ) -> impl Iterator<Item = Self> + ExactSizeIterator { let ctor_sub_tys = cx.ctor_sub_tys(ctor, &self.ty); let ctor_sub_validity = self.validity.specialize(ctor); ctor_sub_tys.map(move |(ty, PrivateUninhabitedField(private_uninhabited))| PlaceInfo { @@ -1046,13 +1046,13 @@ impl<'p, Cx: PatCx> PatStack<'p, Cx> { self.pats[0] } - fn iter(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> + Captures<'_> { + fn iter(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> { self.pats.iter().copied() } // Expand the first or-pattern into its subpatterns. Only useful if the pattern is an // or-pattern. Panics if `self` is empty. - fn expand_or_pat(&self) -> impl Iterator<Item = PatStack<'p, Cx>> + Captures<'_> { + fn expand_or_pat(&self) -> impl Iterator<Item = PatStack<'p, Cx>> { self.head().expand_or_pat().into_iter().map(move |pat| { let mut new = self.clone(); new.pats[0] = pat; @@ -1157,15 +1157,12 @@ impl<'p, Cx: PatCx> MatrixRow<'p, Cx> { self.pats.head() } - fn iter(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> + Captures<'_> { + fn iter(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> { self.pats.iter() } // Expand the first or-pattern (if any) into its subpatterns. Panics if `self` is empty. - fn expand_or_pat( - &self, - parent_row: usize, - ) -> impl Iterator<Item = MatrixRow<'p, Cx>> + Captures<'_> { + fn expand_or_pat(&self, parent_row: usize) -> impl Iterator<Item = MatrixRow<'p, Cx>> { let is_or_pat = self.pats.head().is_or_pat(); self.pats.expand_or_pat().map(move |patstack| MatrixRow { pats: patstack, @@ -1275,7 +1272,7 @@ impl<'p, Cx: PatCx> Matrix<'p, Cx> { } /// Iterate over the first pattern of each row. - fn heads(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> + Clone + Captures<'_> { + fn heads(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> + Clone { self.rows().map(|r| r.head()) } diff --git a/compiler/rustc_pattern_analysis/tests/common/mod.rs b/compiler/rustc_pattern_analysis/tests/common/mod.rs index 23560ad6419..365bc2d863f 100644 --- a/compiler/rustc_pattern_analysis/tests/common/mod.rs +++ b/compiler/rustc_pattern_analysis/tests/common/mod.rs @@ -2,7 +2,7 @@ use rustc_pattern_analysis::constructor::{ Constructor, ConstructorSet, IntRange, MaybeInfiniteInt, RangeEnd, VariantVisibility, }; use rustc_pattern_analysis::usefulness::{PlaceValidity, UsefulnessReport}; -use rustc_pattern_analysis::{Captures, MatchArm, PatCx, PrivateUninhabitedField}; +use rustc_pattern_analysis::{MatchArm, PatCx, PrivateUninhabitedField}; /// Sets up `tracing` for easier debugging. Tries to look like the `rustc` setup. pub fn init_tracing() { @@ -156,12 +156,11 @@ impl PatCx for Cx { ty.sub_tys(ctor).len() } - fn ctor_sub_tys<'a>( - &'a self, - ctor: &'a Constructor<Self>, - ty: &'a Self::Ty, - ) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator + Captures<'a> - { + fn ctor_sub_tys( + &self, + ctor: &Constructor<Self>, + ty: &Self::Ty, + ) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator { ty.sub_tys(ctor).into_iter().map(|ty| (ty, PrivateUninhabitedField(false))) } |
