@@ -1517,7 +1517,14 @@ fn constructor_intersects_pattern<'p, 'a: 'p, 'tcx: 'a>(
15171517) -> Option < Vec < & ' p Pattern < ' tcx > > > {
15181518 if should_treat_range_exhaustively ( tcx, ctor) {
15191519 match ( IntRange :: from_ctor ( tcx, ctor) , IntRange :: from_pat ( tcx, pat) ) {
1520- ( Some ( ctor) , Some ( pat) ) => ctor. intersection ( & pat) . map ( |_| vec ! [ ] ) ,
1520+ ( Some ( ctor) , Some ( pat) ) => {
1521+ ctor. intersection ( & pat) . map ( |_| {
1522+ let ( pat_lo, pat_hi) = pat. range . into_inner ( ) ;
1523+ let ( ctor_lo, ctor_hi) = ctor. range . into_inner ( ) ;
1524+ assert ! ( pat_lo <= ctor_lo && ctor_hi <= pat_hi) ;
1525+ Some ( vec ! [ ] )
1526+ } )
1527+ }
15211528 _ => None ,
15221529 }
15231530 } else {
@@ -1656,21 +1663,18 @@ fn specialize<'p, 'a: 'p, 'tcx: 'a>(
16561663 }
16571664 }
16581665 _ => {
1659- // If the constructor is a single value, we add a row to the specialised matrix
1660- // if the pattern is equal to the constructor. If the constructor is a range of
1661- // values, we add a row to the specialised matrix if the pattern is contained
1662- // within the constructor. These two cases (for a single value pattern) can be
1663- // treated as intersection.
1666+ // If the constructor is a:
1667+ // Single value: add a row if the constructor equals the pattern.
1668+ // Range: add a row if the constructor contains the pattern.
16641669 constructor_intersects_pattern ( cx. tcx , constructor, pat)
16651670 }
16661671 }
16671672 }
16681673
16691674 PatternKind :: Range { .. } => {
1670- // If the constructor is a single value, we add a row to the specialised matrix if the
1671- // pattern contains the constructor. If the constructor is a range of values, we add a
1672- // row to the specialised matrix if there exists any value that lies both within the
1673- // pattern and the constructor. These two cases reduce to intersection.
1675+ // If the constructor is a:
1676+ // Single value: add a row if the pattern contains the constructor.
1677+ // Range: add a row if the constructor intersects the pattern.
16741678 constructor_intersects_pattern ( cx. tcx , constructor, pat)
16751679 }
16761680
0 commit comments