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
|
@ -2456,9 +2456,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
LitToConstInput { lit: &lit.node, ty, neg: negated };
|
||||
let ct = match tcx.lit_to_const(lit_input) {
|
||||
Ok(c) => c,
|
||||
Err(LitToConstError::Reported(err)) => {
|
||||
ty::Const::new_error(tcx, err)
|
||||
}
|
||||
Err(LitToConstError::TypeError) => todo!(),
|
||||
};
|
||||
(ct, ty)
|
||||
|
|
|
@ -16,7 +16,6 @@ use rustc_abi::{AddressSpace, Align, Endian, HasDataLayout, Size};
|
|||
use rustc_ast::{LitKind, Mutability};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sync::Lock;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
|
||||
|
@ -91,7 +90,6 @@ pub enum LitToConstError {
|
|||
/// This is used for graceful error handling (`span_delayed_bug`) in
|
||||
/// type checking (`Const::from_anon_const`).
|
||||
TypeError,
|
||||
Reported(ErrorGuaranteed),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
|
|
|
@ -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"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,7 +120,6 @@ fn recurse_build<'tcx>(
|
|||
let sp = node.span;
|
||||
match tcx.at(sp).lit_to_const(LitToConstInput { lit: &lit.node, ty: node.ty, neg }) {
|
||||
Ok(c) => c,
|
||||
Err(LitToConstError::Reported(guar)) => ty::Const::new_error(tcx, guar),
|
||||
Err(LitToConstError::TypeError) => {
|
||||
bug!("encountered type error in lit_to_const")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue