Skip to content

Commit adf4ef7

Browse files
committed
Use LitToConstError rather than bool for errors
1 parent 4d66b65 commit adf4ef7

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/librustc/ty/layout.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1115,13 +1115,10 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
11151115
}
11161116
tcx.layout_raw(param_env.and(normalized))?
11171117
}
1118-
ty::TyParam(_) => {
1119-
return Err(LayoutError::Unknown(ty));
1120-
}
11211118
ty::TyGeneratorWitness(..) | ty::TyInfer(_) => {
11221119
bug!("LayoutDetails::compute: unexpected type `{}`", ty)
11231120
}
1124-
ty::TyError => {
1121+
ty::TyParam(_) | ty::TyError => {
11251122
return Err(LayoutError::Unknown(ty));
11261123
}
11271124
})

src/librustc_mir/hair/pattern/mod.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,8 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
743743
);
744744
*self.const_to_pat(instance, val, expr.hir_id, lit.span).kind
745745
},
746-
Err(float_bug) => {
747-
if float_bug {
746+
Err(e) => {
747+
if e == LitToConstError::UnparseableFloat {
748748
self.errors.push(PatternError::FloatBug);
749749
}
750750
PatternKind::Wild
@@ -766,8 +766,8 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
766766
);
767767
*self.const_to_pat(instance, val, expr.hir_id, lit.span).kind
768768
},
769-
Err(float_bug) => {
770-
if float_bug {
769+
Err(e) => {
770+
if e == LitToConstError::UnparseableFloat {
771771
self.errors.push(PatternError::FloatBug);
772772
}
773773
PatternKind::Wild
@@ -1122,12 +1122,18 @@ pub fn compare_const_vals<'a, 'tcx>(
11221122
fallback()
11231123
}
11241124

1125+
#[derive(PartialEq)]
1126+
enum LitToConstError {
1127+
UnparseableFloat,
1128+
Propagated,
1129+
}
1130+
11251131
// FIXME: Combine with rustc_mir::hair::cx::const_eval_literal
11261132
fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind,
11271133
tcx: TyCtxt<'a, 'tcx, 'tcx>,
11281134
ty: Ty<'tcx>,
11291135
neg: bool)
1130-
-> Result<&'tcx ty::Const<'tcx>, bool> {
1136+
-> Result<&'tcx ty::Const<'tcx>, LitToConstError> {
11311137
use syntax::ast::*;
11321138

11331139
use rustc::mir::interpret::*;
@@ -1156,11 +1162,10 @@ fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind,
11561162
ty::TyInt(other) => Int::Signed(other),
11571163
ty::TyUint(UintTy::Usize) => Int::Unsigned(tcx.sess.target.usize_ty),
11581164
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);
11621167
}
1163-
_ => bug!("{:?}", ty.sty),
1168+
_ => bug!("literal integer type with bad type ({:?})", ty.sty),
11641169
};
11651170
// This converts from LitKind::Int (which is sign extended) to
11661171
// Scalar::Bytes (which is zero extended)
@@ -1190,14 +1195,14 @@ fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind,
11901195
})
11911196
},
11921197
LitKind::Float(n, fty) => {
1193-
parse_float(n, fty, neg).map_err(|_| true)?
1198+
parse_float(n, fty, neg).map_err(|_| LitToConstError::UnparseableFloat)?
11941199
}
11951200
LitKind::FloatUnsuffixed(n) => {
11961201
let fty = match ty.sty {
11971202
ty::TyFloat(fty) => fty,
11981203
_ => bug!()
11991204
};
1200-
parse_float(n, fty, neg).map_err(|_| true)?
1205+
parse_float(n, fty, neg).map_err(|_| LitToConstError::UnparseableFloat)?
12011206
}
12021207
LitKind::Bool(b) => ConstValue::Scalar(Scalar::Bits {
12031208
bits: b as u128,

0 commit comments

Comments
 (0)