Use error constant instead of explicit error handling
This commit is contained in:
parent
7833cf7a47
commit
787af97bab
5 changed files with 3 additions and 10 deletions
|
|
@ -62,13 +62,13 @@ pub(crate) fn lit_to_const<'tcx>(
|
|||
}
|
||||
(ast::LitKind::Bool(b), ty::Bool) => ty::ValTree::from_scalar_int((*b).into()),
|
||||
(ast::LitKind::Float(n, _), ty::Float(fty)) => {
|
||||
let bits = parse_float_into_scalar(*n, *fty, neg).ok_or_else(|| {
|
||||
let bits = parse_float_into_scalar(*n, *fty, neg).unwrap_or_else(|| {
|
||||
tcx.dcx().bug(format!("couldn't parse float literal: {:?}", lit_input.lit))
|
||||
})?;
|
||||
});
|
||||
ty::ValTree::from_scalar_int(bits)
|
||||
}
|
||||
(ast::LitKind::Char(c), ty::Char) => ty::ValTree::from_scalar_int((*c).into()),
|
||||
(ast::LitKind::Err(guar), _) => return Err(LitToConstError::Reported(*guar)),
|
||||
(ast::LitKind::Err(guar), _) => return Ok(ty::Const::new_error(tcx, *guar)),
|
||||
_ => return Err(LitToConstError::TypeError),
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -671,7 +671,6 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
let lit_input = LitToConstInput { lit: &lit.node, ty: ct_ty, neg };
|
||||
match self.tcx.at(expr.span).lit_to_const(lit_input) {
|
||||
Ok(constant) => self.const_to_pat(constant, ct_ty, expr.hir_id, lit.span).kind,
|
||||
Err(LitToConstError::Reported(e)) => PatKind::Error(e),
|
||||
Err(LitToConstError::TypeError) => bug!("lower_lit: had type error"),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue