@@ -1360,6 +1360,19 @@ fn slice_pat_covered_by_constructor<'tcx>(
1360
1360
Ok ( true )
1361
1361
}
1362
1362
1363
+ // Whether to evaluate a constructor using exhaustive integer matching. This is true if the
1364
+ // constructor is a range or constant with an integer type.
1365
+ fn should_treat_range_exhaustively ( tcx : TyCtxt < ' _ , ' tcx , ' tcx > , ctor : & Constructor < ' tcx > ) -> bool {
1366
+ if tcx. features ( ) . exhaustive_integer_patterns {
1367
+ if let ConstantValue ( value) | ConstantRange ( value, _, _) = ctor {
1368
+ if let ty:: TyChar | ty:: TyInt ( _) | ty:: TyUint ( _) = value. ty . sty {
1369
+ return true ;
1370
+ }
1371
+ }
1372
+ }
1373
+ false
1374
+ }
1375
+
1363
1376
/// For exhaustive integer matching, some constructors are grouped within other constructors
1364
1377
/// (namely integer typed values are grouped within ranges). However, when specialising these
1365
1378
/// constructors, we want to be specialising for the underlying constructors (the integers), not
@@ -1394,7 +1407,7 @@ fn split_grouped_constructors<'p, 'a: 'p, 'tcx: 'a>(
1394
1407
match ctor {
1395
1408
// For now, only ranges may denote groups of "subconstructors", so we only need to
1396
1409
// special-case constant ranges.
1397
- ConstantRange ( ..) => {
1410
+ ConstantRange ( ..) if should_treat_range_exhaustively ( tcx , & ctor ) => {
1398
1411
// We only care about finding all the subranges within the range of the intersection
1399
1412
// of the new pattern `p_({m + 1},1)` (here `pat`) and the constructor range.
1400
1413
// Anything else is irrelevant, because it is guaranteed to result in `NotUseful`,
@@ -1509,13 +1522,7 @@ fn constructor_intersects_pattern<'p, 'a: 'p, 'tcx: 'a>(
1509
1522
ctor : & Constructor < ' tcx > ,
1510
1523
pat : & ' p Pattern < ' tcx > ,
1511
1524
) -> Option < Vec < & ' p Pattern < ' tcx > > > {
1512
- let mut integer_matching = false ;
1513
- if let ConstantValue ( value) | ConstantRange ( value, _, _) = ctor {
1514
- if let ty:: TyChar | ty:: TyInt ( _) | ty:: TyUint ( _) = value. ty . sty {
1515
- integer_matching = true ;
1516
- }
1517
- }
1518
- if integer_matching {
1525
+ if should_treat_range_exhaustively ( tcx, ctor) {
1519
1526
match ( IntRange :: from_ctor ( tcx, ctor) , IntRange :: from_pat ( tcx, pat) ) {
1520
1527
( Some ( ctor) , Some ( pat) ) => ctor. intersection ( & pat) . map ( |_| vec ! [ ] ) ,
1521
1528
_ => None ,
0 commit comments