@@ -140,8 +140,13 @@ impl MaybeInfiniteInt {
140
140
PatRangeBoundary :: PosInfinity => PosInfinity ,
141
141
}
142
142
}
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 > {
145
150
match self {
146
151
NegInfinity => PatRangeBoundary :: NegInfinity ,
147
152
Finite ( x) => {
@@ -326,25 +331,25 @@ impl IntRange {
326
331
/// Whether the range denotes the values before `isize::MIN` or the values after
327
332
/// `usize::MAX`/`isize::MAX`.
328
333
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 `.
330
335
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) ;
333
338
matches ! ( lo, PatRangeBoundary :: PosInfinity )
334
339
|| matches ! ( hi, PatRangeBoundary :: NegInfinity )
335
340
}
336
341
}
337
342
/// 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 > {
339
344
let kind = if matches ! ( ( self . lo, self . hi) , ( NegInfinity , PosInfinity ) ) {
340
345
PatKind :: Wild
341
346
} 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) ;
343
348
let value = lo. as_finite ( ) . unwrap ( ) ;
344
349
PatKind :: Constant { value }
345
350
} 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) ;
348
353
let end = if hi. is_finite ( ) {
349
354
RangeEnd :: Included
350
355
} else {
@@ -1803,13 +1808,14 @@ impl<'tcx> WitnessPat<'tcx> {
1803
1808
self . ty
1804
1809
}
1805
1810
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 > {
1808
1814
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) ) ) ;
1810
1816
let kind = match & self . ctor {
1811
1817
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 ) ,
1813
1819
Single | Variant ( _) => match self . ty . kind ( ) {
1814
1820
ty:: Tuple ( ..) => PatKind :: Leaf {
1815
1821
subpatterns : subpatterns
0 commit comments