Remove the unused overlapping_range_endpoints Vec

This commit is contained in:
Nadrieril 2024-01-15 19:26:55 +01:00
parent 8b66f497eb
commit 448c4a4efb
2 changed files with 5 additions and 39 deletions

View File

@ -32,8 +32,6 @@ pub type DeconstructedPat<'p, 'tcx> =
crate::pat::DeconstructedPat<'p, RustcMatchCheckCtxt<'p, 'tcx>>; crate::pat::DeconstructedPat<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcMatchCheckCtxt<'p, 'tcx>>; pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
pub type MatchCtxt<'a, 'p, 'tcx> = crate::MatchCtxt<'a, RustcMatchCheckCtxt<'p, 'tcx>>; pub type MatchCtxt<'a, 'p, 'tcx> = crate::MatchCtxt<'a, RustcMatchCheckCtxt<'p, 'tcx>>;
pub type OverlappingRanges<'p, 'tcx> =
crate::usefulness::OverlappingRanges<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
pub(crate) type PlaceCtxt<'a, 'p, 'tcx> = pub(crate) type PlaceCtxt<'a, 'p, 'tcx> =
crate::usefulness::PlaceCtxt<'a, RustcMatchCheckCtxt<'p, 'tcx>>; crate::usefulness::PlaceCtxt<'a, RustcMatchCheckCtxt<'p, 'tcx>>;
pub(crate) type SplitConstructorSet<'p, 'tcx> = pub(crate) type SplitConstructorSet<'p, 'tcx> =

View File

@ -1344,7 +1344,6 @@ fn collect_overlapping_range_endpoints<'p, Cx: TypeCx>(
overlap_range: IntRange, overlap_range: IntRange,
matrix: &Matrix<'p, Cx>, matrix: &Matrix<'p, Cx>,
specialized_matrix: &Matrix<'p, Cx>, specialized_matrix: &Matrix<'p, Cx>,
_overlapping_range_endpoints: &mut Vec<OverlappingRanges<'p, Cx>>,
) { ) {
let overlap = overlap_range.lo; let overlap = overlap_range.lo;
// Ranges that look like `lo..=overlap`. // Ranges that look like `lo..=overlap`.
@ -1416,7 +1415,6 @@ fn collect_overlapping_range_endpoints<'p, Cx: TypeCx>(
fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>( fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
mcx: MatchCtxt<'a, Cx>, mcx: MatchCtxt<'a, Cx>,
matrix: &mut Matrix<'p, Cx>, matrix: &mut Matrix<'p, Cx>,
overlapping_range_endpoints: &mut Vec<OverlappingRanges<'p, Cx>>,
is_top_level: bool, is_top_level: bool,
) -> Result<WitnessMatrix<Cx>, Cx::Error> { ) -> Result<WitnessMatrix<Cx>, Cx::Error> {
debug_assert!(matrix.rows().all(|r| r.len() == matrix.column_count())); debug_assert!(matrix.rows().all(|r| r.len() == matrix.column_count()));
@ -1496,12 +1494,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
let ctor_is_relevant = matches!(ctor, Constructor::Missing) || missing_ctors.is_empty(); let ctor_is_relevant = matches!(ctor, Constructor::Missing) || missing_ctors.is_empty();
let mut spec_matrix = matrix.specialize_constructor(pcx, &ctor, ctor_is_relevant); let mut spec_matrix = matrix.specialize_constructor(pcx, &ctor, ctor_is_relevant);
let mut witnesses = ensure_sufficient_stack(|| { let mut witnesses = ensure_sufficient_stack(|| {
compute_exhaustiveness_and_usefulness( compute_exhaustiveness_and_usefulness(mcx, &mut spec_matrix, false)
mcx,
&mut spec_matrix,
overlapping_range_endpoints,
false,
)
})?; })?;
// Transform witnesses for `spec_matrix` into witnesses for `matrix`. // Transform witnesses for `spec_matrix` into witnesses for `matrix`.
@ -1530,13 +1523,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
&& spec_matrix.rows.len() >= 2 && spec_matrix.rows.len() >= 2
&& spec_matrix.rows.iter().any(|row| !row.intersects.is_empty()) && spec_matrix.rows.iter().any(|row| !row.intersects.is_empty())
{ {
collect_overlapping_range_endpoints( collect_overlapping_range_endpoints(mcx, overlap_range, matrix, &spec_matrix);
mcx,
overlap_range,
matrix,
&spec_matrix,
overlapping_range_endpoints,
);
} }
} }
} }
@ -1563,15 +1550,6 @@ pub enum Usefulness<'p, Cx: TypeCx> {
Redundant, Redundant,
} }
/// Indicates that the range `pat` overlapped with all the ranges in `overlaps_with`, where the
/// range they overlapped over is `overlaps_on`. We only detect singleton overlaps.
#[derive(Clone, Debug)]
pub struct OverlappingRanges<'p, Cx: TypeCx> {
pub pat: &'p DeconstructedPat<'p, Cx>,
pub overlaps_on: IntRange,
pub overlaps_with: Vec<&'p DeconstructedPat<'p, Cx>>,
}
/// The output of checking a match for exhaustiveness and arm usefulness. /// The output of checking a match for exhaustiveness and arm usefulness.
pub struct UsefulnessReport<'p, Cx: TypeCx> { pub struct UsefulnessReport<'p, Cx: TypeCx> {
/// For each arm of the input, whether that arm is useful after the arms above it. /// For each arm of the input, whether that arm is useful after the arms above it.
@ -1579,7 +1557,6 @@ pub struct UsefulnessReport<'p, Cx: TypeCx> {
/// If the match is exhaustive, this is empty. If not, this contains witnesses for the lack of /// If the match is exhaustive, this is empty. If not, this contains witnesses for the lack of
/// exhaustiveness. /// exhaustiveness.
pub non_exhaustiveness_witnesses: Vec<WitnessPat<Cx>>, pub non_exhaustiveness_witnesses: Vec<WitnessPat<Cx>>,
pub overlapping_range_endpoints: Vec<OverlappingRanges<'p, Cx>>,
} }
/// Computes whether a match is exhaustive and which of its arms are useful. /// Computes whether a match is exhaustive and which of its arms are useful.
@ -1590,14 +1567,9 @@ pub fn compute_match_usefulness<'p, Cx: TypeCx>(
scrut_ty: Cx::Ty, scrut_ty: Cx::Ty,
scrut_validity: ValidityConstraint, scrut_validity: ValidityConstraint,
) -> Result<UsefulnessReport<'p, Cx>, Cx::Error> { ) -> Result<UsefulnessReport<'p, Cx>, Cx::Error> {
let mut overlapping_range_endpoints = Vec::new();
let mut matrix = Matrix::new(arms, scrut_ty, scrut_validity); let mut matrix = Matrix::new(arms, scrut_ty, scrut_validity);
let non_exhaustiveness_witnesses = compute_exhaustiveness_and_usefulness( let non_exhaustiveness_witnesses =
cx, compute_exhaustiveness_and_usefulness(cx, &mut matrix, true)?;
&mut matrix,
&mut overlapping_range_endpoints,
true,
)?;
let non_exhaustiveness_witnesses: Vec<_> = non_exhaustiveness_witnesses.single_column(); let non_exhaustiveness_witnesses: Vec<_> = non_exhaustiveness_witnesses.single_column();
let arm_usefulness: Vec<_> = arms let arm_usefulness: Vec<_> = arms
@ -1615,9 +1587,5 @@ pub fn compute_match_usefulness<'p, Cx: TypeCx>(
}) })
.collect(); .collect();
Ok(UsefulnessReport { Ok(UsefulnessReport { arm_usefulness, non_exhaustiveness_witnesses })
arm_usefulness,
non_exhaustiveness_witnesses,
overlapping_range_endpoints,
})
} }