@@ -743,8 +743,8 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
743
743
) ;
744
744
* self . const_to_pat ( instance, val, expr. hir_id , lit. span ) . kind
745
745
} ,
746
- Err ( float_bug ) => {
747
- if float_bug {
746
+ Err ( e ) => {
747
+ if e == LitToConstError :: UnparseableFloat {
748
748
self . errors . push ( PatternError :: FloatBug ) ;
749
749
}
750
750
PatternKind :: Wild
@@ -766,8 +766,8 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
766
766
) ;
767
767
* self . const_to_pat ( instance, val, expr. hir_id , lit. span ) . kind
768
768
} ,
769
- Err ( float_bug ) => {
770
- if float_bug {
769
+ Err ( e ) => {
770
+ if e == LitToConstError :: UnparseableFloat {
771
771
self . errors . push ( PatternError :: FloatBug ) ;
772
772
}
773
773
PatternKind :: Wild
@@ -1122,12 +1122,18 @@ pub fn compare_const_vals<'a, 'tcx>(
1122
1122
fallback ( )
1123
1123
}
1124
1124
1125
+ #[ derive( PartialEq ) ]
1126
+ enum LitToConstError {
1127
+ UnparseableFloat ,
1128
+ Propagated ,
1129
+ }
1130
+
1125
1131
// FIXME: Combine with rustc_mir::hair::cx::const_eval_literal
1126
1132
fn lit_to_const < ' a , ' tcx > ( lit : & ' tcx ast:: LitKind ,
1127
1133
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1128
1134
ty : Ty < ' tcx > ,
1129
1135
neg : bool )
1130
- -> Result < & ' tcx ty:: Const < ' tcx > , bool > {
1136
+ -> Result < & ' tcx ty:: Const < ' tcx > , LitToConstError > {
1131
1137
use syntax:: ast:: * ;
1132
1138
1133
1139
use rustc:: mir:: interpret:: * ;
@@ -1156,11 +1162,10 @@ fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind,
1156
1162
ty:: TyInt ( other) => Int :: Signed ( other) ,
1157
1163
ty:: TyUint ( UintTy :: Usize ) => Int :: Unsigned ( tcx. sess . target . usize_ty ) ,
1158
1164
ty:: TyUint ( other) => Int :: Unsigned ( other) ,
1159
- ty:: TyError => {
1160
- // Avoid ICE
1161
- return Err ( false ) ;
1165
+ ty:: TyError => { // Avoid ICE (#51963)
1166
+ return Err ( LitToConstError :: Propagated ) ;
1162
1167
}
1163
- _ => bug ! ( "{:?}" , ty. sty) ,
1168
+ _ => bug ! ( "literal integer type with bad type ( {:?}) " , ty. sty) ,
1164
1169
} ;
1165
1170
// This converts from LitKind::Int (which is sign extended) to
1166
1171
// Scalar::Bytes (which is zero extended)
@@ -1190,14 +1195,14 @@ fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind,
1190
1195
} )
1191
1196
} ,
1192
1197
LitKind :: Float ( n, fty) => {
1193
- parse_float ( n, fty, neg) . map_err ( |_| true ) ?
1198
+ parse_float ( n, fty, neg) . map_err ( |_| LitToConstError :: UnparseableFloat ) ?
1194
1199
}
1195
1200
LitKind :: FloatUnsuffixed ( n) => {
1196
1201
let fty = match ty. sty {
1197
1202
ty:: TyFloat ( fty) => fty,
1198
1203
_ => bug ! ( )
1199
1204
} ;
1200
- parse_float ( n, fty, neg) . map_err ( |_| true ) ?
1205
+ parse_float ( n, fty, neg) . map_err ( |_| LitToConstError :: UnparseableFloat ) ?
1201
1206
}
1202
1207
LitKind :: Bool ( b) => ConstValue :: Scalar ( Scalar :: Bits {
1203
1208
bits : b as u128 ,
0 commit comments