@@ -1360,6 +1360,19 @@ fn slice_pat_covered_by_constructor<'tcx>(
13601360 Ok ( true )
13611361}
13621362
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+
13631376/// For exhaustive integer matching, some constructors are grouped within other constructors
13641377/// (namely integer typed values are grouped within ranges). However, when specialising these
13651378/// 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>(
13941407 match ctor {
13951408 // For now, only ranges may denote groups of "subconstructors", so we only need to
13961409 // special-case constant ranges.
1397- ConstantRange ( ..) => {
1410+ ConstantRange ( ..) if should_treat_range_exhaustively ( tcx , & ctor ) => {
13981411 // We only care about finding all the subranges within the range of the intersection
13991412 // of the new pattern `p_({m + 1},1)` (here `pat`) and the constructor range.
14001413 // 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>(
15091522 ctor : & Constructor < ' tcx > ,
15101523 pat : & ' p Pattern < ' tcx > ,
15111524) -> 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) {
15191526 match ( IntRange :: from_ctor ( tcx, ctor) , IntRange :: from_pat ( tcx, pat) ) {
15201527 ( Some ( ctor) , Some ( pat) ) => ctor. intersection ( & pat) . map ( |_| vec ! [ ] ) ,
15211528 _ => None ,
0 commit comments