@@ -1340,10 +1340,10 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
13401340/// We can however get false negatives because exhaustiveness does not explore all cases. See the
13411341/// section on relevancy at the top of the file.
13421342fn collect_overlapping_range_endpoints < ' p , Cx : TypeCx > (
1343+ mcx : MatchCtxt < ' _ , Cx > ,
13431344 overlap_range : IntRange ,
13441345 matrix : & Matrix < ' p , Cx > ,
13451346 specialized_matrix : & Matrix < ' p , Cx > ,
1346- overlapping_range_endpoints : & mut Vec < OverlappingRanges < ' p , Cx > > ,
13471347) {
13481348 let overlap = overlap_range. lo ;
13491349 // Ranges that look like `lo..=overlap`.
@@ -1373,11 +1373,7 @@ fn collect_overlapping_range_endpoints<'p, Cx: TypeCx>(
13731373 . map ( |& ( _, pat) | pat)
13741374 . collect ( ) ;
13751375 if !overlaps_with. is_empty ( ) {
1376- overlapping_range_endpoints. push ( OverlappingRanges {
1377- pat,
1378- overlaps_on : overlap_range,
1379- overlaps_with,
1380- } ) ;
1376+ mcx. tycx . lint_overlapping_range_endpoints ( pat, overlap_range, & overlaps_with) ;
13811377 }
13821378 }
13831379 suffixes. push ( ( child_row_id, pat) )
@@ -1393,11 +1389,7 @@ fn collect_overlapping_range_endpoints<'p, Cx: TypeCx>(
13931389 . map ( |& ( _, pat) | pat)
13941390 . collect ( ) ;
13951391 if !overlaps_with. is_empty ( ) {
1396- overlapping_range_endpoints. push ( OverlappingRanges {
1397- pat,
1398- overlaps_on : overlap_range,
1399- overlaps_with,
1400- } ) ;
1392+ mcx. tycx . lint_overlapping_range_endpoints ( pat, overlap_range, & overlaps_with) ;
14011393 }
14021394 }
14031395 prefixes. push ( ( child_row_id, pat) )
@@ -1423,7 +1415,6 @@ fn collect_overlapping_range_endpoints<'p, Cx: TypeCx>(
14231415fn compute_exhaustiveness_and_usefulness < ' a , ' p , Cx : TypeCx > (
14241416 mcx : MatchCtxt < ' a , Cx > ,
14251417 matrix : & mut Matrix < ' p , Cx > ,
1426- overlapping_range_endpoints : & mut Vec < OverlappingRanges < ' p , Cx > > ,
14271418 is_top_level : bool ,
14281419) -> Result < WitnessMatrix < Cx > , Cx :: Error > {
14291420 debug_assert ! ( matrix. rows( ) . all( |r| r. len( ) == matrix. column_count( ) ) ) ;
@@ -1503,12 +1494,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
15031494 let ctor_is_relevant = matches ! ( ctor, Constructor :: Missing ) || missing_ctors. is_empty ( ) ;
15041495 let mut spec_matrix = matrix. specialize_constructor ( pcx, & ctor, ctor_is_relevant) ;
15051496 let mut witnesses = ensure_sufficient_stack ( || {
1506- compute_exhaustiveness_and_usefulness (
1507- mcx,
1508- & mut spec_matrix,
1509- overlapping_range_endpoints,
1510- false ,
1511- )
1497+ compute_exhaustiveness_and_usefulness ( mcx, & mut spec_matrix, false )
15121498 } ) ?;
15131499
15141500 // Transform witnesses for `spec_matrix` into witnesses for `matrix`.
@@ -1537,12 +1523,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
15371523 && spec_matrix. rows . len ( ) >= 2
15381524 && spec_matrix. rows . iter ( ) . any ( |row| !row. intersects . is_empty ( ) )
15391525 {
1540- collect_overlapping_range_endpoints (
1541- overlap_range,
1542- matrix,
1543- & spec_matrix,
1544- overlapping_range_endpoints,
1545- ) ;
1526+ collect_overlapping_range_endpoints ( mcx, overlap_range, matrix, & spec_matrix) ;
15461527 }
15471528 }
15481529 }
@@ -1569,23 +1550,13 @@ pub enum Usefulness<'p, Cx: TypeCx> {
15691550 Redundant ,
15701551}
15711552
1572- /// Indicates that the range `pat` overlapped with all the ranges in `overlaps_with`, where the
1573- /// range they overlapped over is `overlaps_on`. We only detect singleton overlaps.
1574- #[ derive( Clone , Debug ) ]
1575- pub struct OverlappingRanges < ' p , Cx : TypeCx > {
1576- pub pat : & ' p DeconstructedPat < ' p , Cx > ,
1577- pub overlaps_on : IntRange ,
1578- pub overlaps_with : Vec < & ' p DeconstructedPat < ' p , Cx > > ,
1579- }
1580-
15811553/// The output of checking a match for exhaustiveness and arm usefulness.
15821554pub struct UsefulnessReport < ' p , Cx : TypeCx > {
15831555 /// For each arm of the input, whether that arm is useful after the arms above it.
15841556 pub arm_usefulness : Vec < ( MatchArm < ' p , Cx > , Usefulness < ' p , Cx > ) > ,
15851557 /// If the match is exhaustive, this is empty. If not, this contains witnesses for the lack of
15861558 /// exhaustiveness.
15871559 pub non_exhaustiveness_witnesses : Vec < WitnessPat < Cx > > ,
1588- pub overlapping_range_endpoints : Vec < OverlappingRanges < ' p , Cx > > ,
15891560}
15901561
15911562/// Computes whether a match is exhaustive and which of its arms are useful.
@@ -1596,14 +1567,9 @@ pub fn compute_match_usefulness<'p, Cx: TypeCx>(
15961567 scrut_ty : Cx :: Ty ,
15971568 scrut_validity : ValidityConstraint ,
15981569) -> Result < UsefulnessReport < ' p , Cx > , Cx :: Error > {
1599- let mut overlapping_range_endpoints = Vec :: new ( ) ;
16001570 let mut matrix = Matrix :: new ( arms, scrut_ty, scrut_validity) ;
1601- let non_exhaustiveness_witnesses = compute_exhaustiveness_and_usefulness (
1602- cx,
1603- & mut matrix,
1604- & mut overlapping_range_endpoints,
1605- true ,
1606- ) ?;
1571+ let non_exhaustiveness_witnesses =
1572+ compute_exhaustiveness_and_usefulness ( cx, & mut matrix, true ) ?;
16071573
16081574 let non_exhaustiveness_witnesses: Vec < _ > = non_exhaustiveness_witnesses. single_column ( ) ;
16091575 let arm_usefulness: Vec < _ > = arms
@@ -1621,9 +1587,5 @@ pub fn compute_match_usefulness<'p, Cx: TypeCx>(
16211587 } )
16221588 . collect ( ) ;
16231589
1624- Ok ( UsefulnessReport {
1625- arm_usefulness,
1626- non_exhaustiveness_witnesses,
1627- overlapping_range_endpoints,
1628- } )
1590+ Ok ( UsefulnessReport { arm_usefulness, non_exhaustiveness_witnesses } )
16291591}
0 commit comments