Skip to content

Commit 7666bbe

Browse files
committed
Use error constant instead of explicit error handling
1 parent 4f8c98a commit 7666bbe

File tree

5 files changed

+3
-10
lines changed

5 files changed

+3
-10
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -2462,9 +2462,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
24622462
LitToConstInput { lit: &lit.node, ty, neg: neg.is_some() };
24632463
let ct = match tcx.lit_to_const(lit_input) {
24642464
Ok(c) => c,
2465-
Err(LitToConstError::Reported(err)) => {
2466-
ty::Const::new_error(tcx, err)
2467-
}
24682465
Err(LitToConstError::TypeError) => todo!(),
24692466
};
24702467
(ct, ty)

compiler/rustc_middle/src/mir/interpret/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_abi::{AddressSpace, Align, Endian, HasDataLayout, Size};
1616
use rustc_ast::{LitKind, Mutability};
1717
use rustc_data_structures::fx::FxHashMap;
1818
use rustc_data_structures::sync::Lock;
19-
use rustc_errors::ErrorGuaranteed;
2019
use rustc_hir::def::DefKind;
2120
use rustc_hir::def_id::{DefId, LocalDefId};
2221
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
@@ -91,7 +90,6 @@ pub enum LitToConstError {
9190
/// This is used for graceful error handling (`span_delayed_bug`) in
9291
/// type checking (`Const::from_anon_const`).
9392
TypeError,
94-
Reported(ErrorGuaranteed),
9593
}
9694

9795
#[derive(Copy, Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]

compiler/rustc_mir_build/src/thir/constant.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ pub(crate) fn lit_to_const<'tcx>(
6262
}
6363
(ast::LitKind::Bool(b), ty::Bool) => ty::ValTree::from_scalar_int((*b).into()),
6464
(ast::LitKind::Float(n, _), ty::Float(fty)) => {
65-
let bits = parse_float_into_scalar(*n, *fty, neg).ok_or_else(|| {
65+
let bits = parse_float_into_scalar(*n, *fty, neg).unwrap_or_else(|| {
6666
tcx.dcx().bug(format!("couldn't parse float literal: {:?}", lit_input.lit))
67-
})?;
67+
});
6868
ty::ValTree::from_scalar_int(bits)
6969
}
7070
(ast::LitKind::Char(c), ty::Char) => ty::ValTree::from_scalar_int((*c).into()),
71-
(ast::LitKind::Err(guar), _) => return Err(LitToConstError::Reported(*guar)),
71+
(ast::LitKind::Err(guar), _) => return Ok(ty::Const::new_error(tcx, *guar)),
7272
_ => return Err(LitToConstError::TypeError),
7373
};
7474

compiler/rustc_mir_build/src/thir/pattern/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,6 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
681681
let lit_input = LitToConstInput { lit: &lit.node, ty: ct_ty, neg };
682682
match self.tcx.at(expr.span).lit_to_const(lit_input) {
683683
Ok(constant) => self.const_to_pat(constant, ct_ty, expr.hir_id, lit.span).kind,
684-
Err(LitToConstError::Reported(e)) => PatKind::Error(e),
685684
Err(LitToConstError::TypeError) => bug!("lower_lit: had type error"),
686685
}
687686
}

compiler/rustc_ty_utils/src/consts.rs

-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ fn recurse_build<'tcx>(
120120
let sp = node.span;
121121
match tcx.at(sp).lit_to_const(LitToConstInput { lit: &lit.node, ty: node.ty, neg }) {
122122
Ok(c) => c,
123-
Err(LitToConstError::Reported(guar)) => ty::Const::new_error(tcx, guar),
124123
Err(LitToConstError::TypeError) => {
125124
bug!("encountered type error in lit_to_const")
126125
}

0 commit comments

Comments
 (0)