@@ -246,8 +246,9 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
246
246
}
247
247
_ => bug ! ( "bad slice pattern {:?} {:?}" , ctor, ty) ,
248
248
} ,
249
- Bool ( ..) | IntRange ( ..) | F32Range ( ..) | F64Range ( ..) | Str ( ..) | Opaque ( ..)
250
- | Never | NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => & [ ] ,
249
+ Bool ( ..) | IntRange ( ..) | F16Range ( ..) | F32Range ( ..) | F64Range ( ..)
250
+ | F128Range ( ..) | Str ( ..) | Opaque ( ..) | Never | NonExhaustive | Hidden | Missing
251
+ | PrivateUninhabited | Wildcard => & [ ] ,
251
252
Or => {
252
253
bug ! ( "called `Fields::wildcards` on an `Or` ctor" )
253
254
}
@@ -274,8 +275,9 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
274
275
} ,
275
276
Ref => 1 ,
276
277
Slice ( slice) => slice. arity ( ) ,
277
- Bool ( ..) | IntRange ( ..) | F32Range ( ..) | F64Range ( ..) | Str ( ..) | Opaque ( ..)
278
- | Never | NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => 0 ,
278
+ Bool ( ..) | IntRange ( ..) | F16Range ( ..) | F32Range ( ..) | F64Range ( ..)
279
+ | F128Range ( ..) | Str ( ..) | Opaque ( ..) | Never | NonExhaustive | Hidden | Missing
280
+ | PrivateUninhabited | Wildcard => 0 ,
279
281
Or => bug ! ( "The `Or` constructor doesn't have a fixed arity" ) ,
280
282
}
281
283
}
@@ -545,6 +547,18 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
545
547
fields = vec ! [ ] ;
546
548
arity = 0 ;
547
549
}
550
+ ty:: Float ( ty:: FloatTy :: F16 ) => {
551
+ ctor = match value. try_eval_bits ( cx. tcx , cx. param_env ) {
552
+ Some ( bits) => {
553
+ use rustc_apfloat:: Float ;
554
+ let value = rustc_apfloat:: ieee:: Half :: from_bits ( bits) ;
555
+ F16Range ( value, value, RangeEnd :: Included )
556
+ }
557
+ None => Opaque ( OpaqueId :: new ( ) ) ,
558
+ } ;
559
+ fields = vec ! [ ] ;
560
+ arity = 0 ;
561
+ }
548
562
ty:: Float ( ty:: FloatTy :: F32 ) => {
549
563
ctor = match value. try_eval_bits ( cx. tcx , cx. param_env ) {
550
564
Some ( bits) => {
@@ -569,6 +583,18 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
569
583
fields = vec ! [ ] ;
570
584
arity = 0 ;
571
585
}
586
+ ty:: Float ( ty:: FloatTy :: F128 ) => {
587
+ ctor = match value. try_eval_bits ( cx. tcx , cx. param_env ) {
588
+ Some ( bits) => {
589
+ use rustc_apfloat:: Float ;
590
+ let value = rustc_apfloat:: ieee:: Quad :: from_bits ( bits) ;
591
+ F128Range ( value, value, RangeEnd :: Included )
592
+ }
593
+ None => Opaque ( OpaqueId :: new ( ) ) ,
594
+ } ;
595
+ fields = vec ! [ ] ;
596
+ arity = 0 ;
597
+ }
572
598
ty:: Ref ( _, t, _) if t. is_str ( ) => {
573
599
// We want a `&str` constant to behave like a `Deref` pattern, to be compatible
574
600
// with other `Deref` patterns. This could have been done in `const_to_pat`,
@@ -610,7 +636,12 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
610
636
let lo = lo. as_finite ( ) . map ( |c| c. eval_bits ( cx. tcx , cx. param_env ) ) ;
611
637
let hi = hi. as_finite ( ) . map ( |c| c. eval_bits ( cx. tcx , cx. param_env ) ) ;
612
638
match fty {
613
- ty:: FloatTy :: F16 => unimplemented ! ( "f16_f128" ) ,
639
+ ty:: FloatTy :: F16 => {
640
+ use rustc_apfloat:: ieee:: Half ;
641
+ let lo = lo. map ( Half :: from_bits) . unwrap_or ( -Half :: INFINITY ) ;
642
+ let hi = hi. map ( Half :: from_bits) . unwrap_or ( Half :: INFINITY ) ;
643
+ F16Range ( lo, hi, end)
644
+ }
614
645
ty:: FloatTy :: F32 => {
615
646
use rustc_apfloat:: ieee:: Single ;
616
647
let lo = lo. map ( Single :: from_bits) . unwrap_or ( -Single :: INFINITY ) ;
@@ -623,7 +654,12 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
623
654
let hi = hi. map ( Double :: from_bits) . unwrap_or ( Double :: INFINITY ) ;
624
655
F64Range ( lo, hi, end)
625
656
}
626
- ty:: FloatTy :: F128 => unimplemented ! ( "f16_f128" ) ,
657
+ ty:: FloatTy :: F128 => {
658
+ use rustc_apfloat:: ieee:: Quad ;
659
+ let lo = lo. map ( Quad :: from_bits) . unwrap_or ( -Quad :: INFINITY ) ;
660
+ let hi = hi. map ( Quad :: from_bits) . unwrap_or ( Quad :: INFINITY ) ;
661
+ F128Range ( lo, hi, end)
662
+ }
627
663
}
628
664
}
629
665
_ => bug ! ( "invalid type for range pattern: {}" , ty. inner( ) ) ,
@@ -836,7 +872,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
836
872
"trying to convert a `Missing` constructor into a `Pat`; this is probably a bug,
837
873
`Missing` should have been processed in `apply_constructors`"
838
874
) ,
839
- F32Range ( ..) | F64Range ( ..) | Opaque ( ..) | Or => {
875
+ F16Range ( .. ) | F32Range ( ..) | F64Range ( .. ) | F128Range ( ..) | Opaque ( ..) | Or => {
840
876
bug ! ( "can't convert to pattern: {:?}" , pat)
841
877
}
842
878
} ;
0 commit comments