@@ -1340,10 +1340,10 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
1340
1340
/// We can however get false negatives because exhaustiveness does not explore all cases. See the
1341
1341
/// section on relevancy at the top of the file.
1342
1342
fn collect_overlapping_range_endpoints < ' p , Cx : TypeCx > (
1343
+ mcx : MatchCtxt < ' _ , Cx > ,
1343
1344
overlap_range : IntRange ,
1344
1345
matrix : & Matrix < ' p , Cx > ,
1345
1346
specialized_matrix : & Matrix < ' p , Cx > ,
1346
- overlapping_range_endpoints : & mut Vec < OverlappingRanges < ' p , Cx > > ,
1347
1347
) {
1348
1348
let overlap = overlap_range. lo ;
1349
1349
// Ranges that look like `lo..=overlap`.
@@ -1373,11 +1373,7 @@ fn collect_overlapping_range_endpoints<'p, Cx: TypeCx>(
1373
1373
. map ( |& ( _, pat) | pat)
1374
1374
. collect ( ) ;
1375
1375
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) ;
1381
1377
}
1382
1378
}
1383
1379
suffixes. push ( ( child_row_id, pat) )
@@ -1393,11 +1389,7 @@ fn collect_overlapping_range_endpoints<'p, Cx: TypeCx>(
1393
1389
. map ( |& ( _, pat) | pat)
1394
1390
. collect ( ) ;
1395
1391
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) ;
1401
1393
}
1402
1394
}
1403
1395
prefixes. push ( ( child_row_id, pat) )
@@ -1423,7 +1415,6 @@ fn collect_overlapping_range_endpoints<'p, Cx: TypeCx>(
1423
1415
fn compute_exhaustiveness_and_usefulness < ' a , ' p , Cx : TypeCx > (
1424
1416
mcx : MatchCtxt < ' a , Cx > ,
1425
1417
matrix : & mut Matrix < ' p , Cx > ,
1426
- overlapping_range_endpoints : & mut Vec < OverlappingRanges < ' p , Cx > > ,
1427
1418
is_top_level : bool ,
1428
1419
) -> Result < WitnessMatrix < Cx > , Cx :: Error > {
1429
1420
debug_assert ! ( matrix. rows( ) . all( |r| r. len( ) == matrix. column_count( ) ) ) ;
@@ -1503,12 +1494,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1503
1494
let ctor_is_relevant = matches ! ( ctor, Constructor :: Missing ) || missing_ctors. is_empty ( ) ;
1504
1495
let mut spec_matrix = matrix. specialize_constructor ( pcx, & ctor, ctor_is_relevant) ;
1505
1496
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 )
1512
1498
} ) ?;
1513
1499
1514
1500
// Transform witnesses for `spec_matrix` into witnesses for `matrix`.
@@ -1537,12 +1523,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1537
1523
&& spec_matrix. rows . len ( ) >= 2
1538
1524
&& spec_matrix. rows . iter ( ) . any ( |row| !row. intersects . is_empty ( ) )
1539
1525
{
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) ;
1546
1527
}
1547
1528
}
1548
1529
}
@@ -1569,23 +1550,13 @@ pub enum Usefulness<'p, Cx: TypeCx> {
1569
1550
Redundant ,
1570
1551
}
1571
1552
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
-
1581
1553
/// The output of checking a match for exhaustiveness and arm usefulness.
1582
1554
pub struct UsefulnessReport < ' p , Cx : TypeCx > {
1583
1555
/// For each arm of the input, whether that arm is useful after the arms above it.
1584
1556
pub arm_usefulness : Vec < ( MatchArm < ' p , Cx > , Usefulness < ' p , Cx > ) > ,
1585
1557
/// If the match is exhaustive, this is empty. If not, this contains witnesses for the lack of
1586
1558
/// exhaustiveness.
1587
1559
pub non_exhaustiveness_witnesses : Vec < WitnessPat < Cx > > ,
1588
- pub overlapping_range_endpoints : Vec < OverlappingRanges < ' p , Cx > > ,
1589
1560
}
1590
1561
1591
1562
/// 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>(
1596
1567
scrut_ty : Cx :: Ty ,
1597
1568
scrut_validity : ValidityConstraint ,
1598
1569
) -> Result < UsefulnessReport < ' p , Cx > , Cx :: Error > {
1599
- let mut overlapping_range_endpoints = Vec :: new ( ) ;
1600
1570
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 ) ?;
1607
1573
1608
1574
let non_exhaustiveness_witnesses: Vec < _ > = non_exhaustiveness_witnesses. single_column ( ) ;
1609
1575
let arm_usefulness: Vec < _ > = arms
@@ -1621,9 +1587,5 @@ pub fn compute_match_usefulness<'p, Cx: TypeCx>(
1621
1587
} )
1622
1588
. collect ( ) ;
1623
1589
1624
- Ok ( UsefulnessReport {
1625
- arm_usefulness,
1626
- non_exhaustiveness_witnesses,
1627
- overlapping_range_endpoints,
1628
- } )
1590
+ Ok ( UsefulnessReport { arm_usefulness, non_exhaustiveness_witnesses } )
1629
1591
}
0 commit comments