);
*self.const_to_pat(instance, val, expr.hir_id, lit.span).kind
},
- Err(float_bug) => {
- if float_bug {
+ Err(e) => {
+ if e == LitToConstError::UnparseableFloat {
self.errors.push(PatternError::FloatBug);
}
PatternKind::Wild
);
*self.const_to_pat(instance, val, expr.hir_id, lit.span).kind
},
- Err(float_bug) => {
- if float_bug {
+ Err(e) => {
+ if e == LitToConstError::UnparseableFloat {
self.errors.push(PatternError::FloatBug);
}
PatternKind::Wild
fallback()
}
+#[derive(PartialEq)]
+enum LitToConstError {
+ UnparseableFloat,
+ Propagated,
+}
+
// FIXME: Combine with rustc_mir::hair::cx::const_eval_literal
fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
ty: Ty<'tcx>,
neg: bool)
- -> Result<&'tcx ty::Const<'tcx>, bool> {
+ -> Result<&'tcx ty::Const<'tcx>, LitToConstError> {
use syntax::ast::*;
use rustc::mir::interpret::*;
ty::TyInt(other) => Int::Signed(other),
ty::TyUint(UintTy::Usize) => Int::Unsigned(tcx.sess.target.usize_ty),
ty::TyUint(other) => Int::Unsigned(other),
- ty::TyError => {
- // Avoid ICE
- return Err(false);
+ ty::TyError => { // Avoid ICE (#51963)
+ return Err(LitToConstError::Propagated);
}
- _ => bug!("{:?}", ty.sty),
+ _ => bug!("literal integer type with bad type ({:?})", ty.sty),
};
// This converts from LitKind::Int (which is sign extended) to
// Scalar::Bytes (which is zero extended)
})
},
LitKind::Float(n, fty) => {
- parse_float(n, fty, neg).map_err(|_| true)?
+ parse_float(n, fty, neg).map_err(|_| LitToConstError::UnparseableFloat)?
}
LitKind::FloatUnsuffixed(n) => {
let fty = match ty.sty {
ty::TyFloat(fty) => fty,
_ => bug!()
};
- parse_float(n, fty, neg).map_err(|_| true)?
+ parse_float(n, fty, neg).map_err(|_| LitToConstError::UnparseableFloat)?
}
LitKind::Bool(b) => ConstValue::Scalar(Scalar::Bits {
bits: b as u128,