diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-05-23 10:54:52 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-05-30 16:03:24 +0000 |
| commit | e40b51da63e0f313e5a9958c3417e241ba600b4e (patch) | |
| tree | 3e5c73e603a817fef45750f75c36e0a935856810 | |
| parent | f8b5e0064b1f89817b5fc52b146ee6f90157cfee (diff) | |
| download | rust-e40b51da63e0f313e5a9958c3417e241ba600b4e.tar.gz rust-e40b51da63e0f313e5a9958c3417e241ba600b4e.zip | |
Get `lit_to_const` in sync with `const_to_valtree_inner`
Without this, we'd have a discrepancy where float literals are not lowered to valtrees, but float constants are.
| -rw-r--r-- | compiler/rustc_mir_build/src/thir/constant.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/compiler/rustc_mir_build/src/thir/constant.rs b/compiler/rustc_mir_build/src/thir/constant.rs index 57ae6a3652d..0b7a9646369 100644 --- a/compiler/rustc_mir_build/src/thir/constant.rs +++ b/compiler/rustc_mir_build/src/thir/constant.rs @@ -3,6 +3,8 @@ use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput}; use rustc_middle::ty::{self, ParamEnv, ScalarInt, TyCtxt}; use rustc_span::DUMMY_SP; +use crate::build::parse_float_into_scalar; + pub(crate) fn lit_to_const<'tcx>( tcx: TyCtxt<'tcx>, lit_input: LitToConstInput<'tcx>, @@ -52,6 +54,17 @@ pub(crate) fn lit_to_const<'tcx>( ty::ValTree::from_scalar_int(scalar_int) } (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(|| { + LitToConstError::Reported(tcx.sess.delay_span_bug( + DUMMY_SP, + format!("couldn't parse float literal: {:?}", lit_input.lit), + )) + })? + .assert_int(); + ty::ValTree::from_scalar_int(bits) + } (ast::LitKind::Char(c), ty::Char) => ty::ValTree::from_scalar_int((*c).into()), (ast::LitKind::Err, _) => { return Err(LitToConstError::Reported( |
