@@ -142,8 +142,13 @@ impl MaybeInfiniteInt {
142
142
PatRangeBoundary :: PosInfinity => PosInfinity ,
143
143
}
144
144
}
145
- // This could change from finite to infinite if we got `usize::MAX+1` after range splitting.
146
- fn to_pat_range_bdy < ' tcx > ( self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> PatRangeBoundary < ' tcx > {
145
+ /// Used only for diagnostics.
146
+ /// This could change from finite to infinite if we got `usize::MAX+1` after range splitting.
147
+ fn to_diagnostic_pat_range_bdy < ' tcx > (
148
+ self ,
149
+ ty : Ty < ' tcx > ,
150
+ tcx : TyCtxt < ' tcx > ,
151
+ ) -> PatRangeBoundary < ' tcx > {
147
152
match self {
148
153
NegInfinity => PatRangeBoundary :: NegInfinity ,
149
154
Finite ( x) => {
@@ -346,25 +351,25 @@ impl IntRange {
346
351
/// Whether the range denotes the values before `isize::MIN` or the values after
347
352
/// `usize::MAX`/`isize::MAX`.
348
353
pub ( crate ) fn is_beyond_boundaries < ' tcx > ( & self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> bool {
349
- // First check if we are usize/isize to avoid unnecessary `to_pat_range_bdy `.
354
+ // First check if we are usize/isize to avoid unnecessary `to_diagnostic_pat_range_bdy `.
350
355
ty. is_ptr_sized_integral ( ) && !tcx. features ( ) . precise_pointer_size_matching && {
351
- let lo = self . lo . to_pat_range_bdy ( ty, tcx) ;
352
- let hi = self . hi . to_pat_range_bdy ( ty, tcx) ;
356
+ let lo = self . lo . to_diagnostic_pat_range_bdy ( ty, tcx) ;
357
+ let hi = self . hi . to_diagnostic_pat_range_bdy ( ty, tcx) ;
353
358
matches ! ( lo, PatRangeBoundary :: PosInfinity )
354
359
|| matches ! ( hi, PatRangeBoundary :: NegInfinity )
355
360
}
356
361
}
357
362
/// Only used for displaying the range.
358
- fn to_pat < ' tcx > ( & self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Pat < ' tcx > {
363
+ fn to_diagnostic_pat < ' tcx > ( & self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Pat < ' tcx > {
359
364
let kind = if matches ! ( ( self . lo, self . hi) , ( NegInfinity , PosInfinity ) ) {
360
365
PatKind :: Wild
361
366
} else if self . is_singleton ( ) {
362
- let lo = self . lo . to_pat_range_bdy ( ty, tcx) ;
367
+ let lo = self . lo . to_diagnostic_pat_range_bdy ( ty, tcx) ;
363
368
let value = lo. as_finite ( ) . unwrap ( ) ;
364
369
PatKind :: Constant { value }
365
370
} else {
366
- let mut lo = self . lo . to_pat_range_bdy ( ty, tcx) ;
367
- let mut hi = self . hi . to_pat_range_bdy ( ty, tcx) ;
371
+ let mut lo = self . lo . to_diagnostic_pat_range_bdy ( ty, tcx) ;
372
+ let mut hi = self . hi . to_diagnostic_pat_range_bdy ( ty, tcx) ;
368
373
let end = if hi. is_finite ( ) {
369
374
RangeEnd :: Included
370
375
} else {
@@ -421,7 +426,7 @@ impl IntRange {
421
426
. filter_map ( |pat| Some ( ( pat. ctor ( ) . as_int_range ( ) ?, pat. span ( ) ) ) )
422
427
. filter ( |( range, _) | self . suspicious_intersection ( range) )
423
428
. map ( |( range, span) | Overlap {
424
- range : self . intersection ( & range) . unwrap ( ) . to_pat ( pcx. ty , pcx. cx . tcx ) ,
429
+ range : self . intersection ( & range) . unwrap ( ) . to_diagnostic_pat ( pcx. ty , pcx. cx . tcx ) ,
425
430
span,
426
431
} )
427
432
. collect ( ) ;
@@ -1867,13 +1872,14 @@ impl<'tcx> WitnessPat<'tcx> {
1867
1872
self . ty
1868
1873
}
1869
1874
1870
- /// Convert back to a `thir::Pat` for diagnostic purposes.
1871
- pub ( crate ) fn to_pat ( & self , cx : & MatchCheckCtxt < ' _ , ' tcx > ) -> Pat < ' tcx > {
1875
+ /// Convert back to a `thir::Pat` for diagnostic purposes. This panics for patterns that don't
1876
+ /// appear in diagnostics, like float ranges.
1877
+ pub ( crate ) fn to_diagnostic_pat ( & self , cx : & MatchCheckCtxt < ' _ , ' tcx > ) -> Pat < ' tcx > {
1872
1878
let is_wildcard = |pat : & Pat < ' _ > | matches ! ( pat. kind, PatKind :: Wild ) ;
1873
- let mut subpatterns = self . iter_fields ( ) . map ( |p| Box :: new ( p. to_pat ( cx) ) ) ;
1879
+ let mut subpatterns = self . iter_fields ( ) . map ( |p| Box :: new ( p. to_diagnostic_pat ( cx) ) ) ;
1874
1880
let kind = match & self . ctor {
1875
1881
Bool ( b) => PatKind :: Constant { value : mir:: Const :: from_bool ( cx. tcx , * b) } ,
1876
- IntRange ( range) => return range. to_pat ( self . ty , cx. tcx ) ,
1882
+ IntRange ( range) => return range. to_diagnostic_pat ( self . ty , cx. tcx ) ,
1877
1883
Single | Variant ( _) => match self . ty . kind ( ) {
1878
1884
ty:: Tuple ( ..) => PatKind :: Leaf {
1879
1885
subpatterns : subpatterns
0 commit comments