@@ -140,8 +140,13 @@ impl MaybeInfiniteInt {
140140 PatRangeBoundary :: PosInfinity => PosInfinity ,
141141 }
142142 }
143- // This could change from finite to infinite if we got `usize::MAX+1` after range splitting.
144- fn to_pat_range_bdy < ' tcx > ( self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> PatRangeBoundary < ' tcx > {
143+ /// Used only for diagnostics.
144+ /// This could change from finite to infinite if we got `usize::MAX+1` after range splitting.
145+ fn to_diagnostic_pat_range_bdy < ' tcx > (
146+ self ,
147+ ty : Ty < ' tcx > ,
148+ tcx : TyCtxt < ' tcx > ,
149+ ) -> PatRangeBoundary < ' tcx > {
145150 match self {
146151 NegInfinity => PatRangeBoundary :: NegInfinity ,
147152 Finite ( x) => {
@@ -326,25 +331,25 @@ impl IntRange {
326331 /// Whether the range denotes the values before `isize::MIN` or the values after
327332 /// `usize::MAX`/`isize::MAX`.
328333 pub ( crate ) fn is_beyond_boundaries < ' tcx > ( & self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> bool {
329- // First check if we are usize/isize to avoid unnecessary `to_pat_range_bdy `.
334+ // First check if we are usize/isize to avoid unnecessary `to_diagnostic_pat_range_bdy `.
330335 ty. is_ptr_sized_integral ( ) && !tcx. features ( ) . precise_pointer_size_matching && {
331- let lo = self . lo . to_pat_range_bdy ( ty, tcx) ;
332- let hi = self . hi . to_pat_range_bdy ( ty, tcx) ;
336+ let lo = self . lo . to_diagnostic_pat_range_bdy ( ty, tcx) ;
337+ let hi = self . hi . to_diagnostic_pat_range_bdy ( ty, tcx) ;
333338 matches ! ( lo, PatRangeBoundary :: PosInfinity )
334339 || matches ! ( hi, PatRangeBoundary :: NegInfinity )
335340 }
336341 }
337342 /// Only used for displaying the range.
338- pub ( super ) fn to_pat < ' tcx > ( & self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Pat < ' tcx > {
343+ pub ( super ) fn to_diagnostic_pat < ' tcx > ( & self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Pat < ' tcx > {
339344 let kind = if matches ! ( ( self . lo, self . hi) , ( NegInfinity , PosInfinity ) ) {
340345 PatKind :: Wild
341346 } else if self . is_singleton ( ) {
342- let lo = self . lo . to_pat_range_bdy ( ty, tcx) ;
347+ let lo = self . lo . to_diagnostic_pat_range_bdy ( ty, tcx) ;
343348 let value = lo. as_finite ( ) . unwrap ( ) ;
344349 PatKind :: Constant { value }
345350 } else {
346- let mut lo = self . lo . to_pat_range_bdy ( ty, tcx) ;
347- let mut hi = self . hi . to_pat_range_bdy ( ty, tcx) ;
351+ let mut lo = self . lo . to_diagnostic_pat_range_bdy ( ty, tcx) ;
352+ let mut hi = self . hi . to_diagnostic_pat_range_bdy ( ty, tcx) ;
348353 let end = if hi. is_finite ( ) {
349354 RangeEnd :: Included
350355 } else {
@@ -1803,13 +1808,14 @@ impl<'tcx> WitnessPat<'tcx> {
18031808 self . ty
18041809 }
18051810
1806- /// Convert back to a `thir::Pat` for diagnostic purposes.
1807- pub ( crate ) fn to_pat ( & self , cx : & MatchCheckCtxt < ' _ , ' tcx > ) -> Pat < ' tcx > {
1811+ /// Convert back to a `thir::Pat` for diagnostic purposes. This panics for patterns that don't
1812+ /// appear in diagnostics, like float ranges.
1813+ pub ( crate ) fn to_diagnostic_pat ( & self , cx : & MatchCheckCtxt < ' _ , ' tcx > ) -> Pat < ' tcx > {
18081814 let is_wildcard = |pat : & Pat < ' _ > | matches ! ( pat. kind, PatKind :: Wild ) ;
1809- let mut subpatterns = self . iter_fields ( ) . map ( |p| Box :: new ( p. to_pat ( cx) ) ) ;
1815+ let mut subpatterns = self . iter_fields ( ) . map ( |p| Box :: new ( p. to_diagnostic_pat ( cx) ) ) ;
18101816 let kind = match & self . ctor {
18111817 Bool ( b) => PatKind :: Constant { value : mir:: Const :: from_bool ( cx. tcx , * b) } ,
1812- IntRange ( range) => return range. to_pat ( self . ty , cx. tcx ) ,
1818+ IntRange ( range) => return range. to_diagnostic_pat ( self . ty , cx. tcx ) ,
18131819 Single | Variant ( _) => match self . ty . kind ( ) {
18141820 ty:: Tuple ( ..) => PatKind :: Leaf {
18151821 subpatterns : subpatterns
0 commit comments