diff options
| author | Eduardo Sánchez Muñoz <eduardosm-dev@e64.io> | 2024-10-14 20:58:32 +0200 |
|---|---|---|
| committer | Eduardo Sánchez Muñoz <eduardosm-dev@e64.io> | 2024-10-14 21:48:51 +0200 |
| commit | b73e613e008fd4a07a52ec7cef7c3af7db716b3d (patch) | |
| tree | 0f6752319c75907a03e146d92fdc08e29f43ca49 /compiler/rustc_const_eval/src/interpret/cast.rs | |
| parent | 8f8bee4f60d9d3769f75c70d558c27a95761c554 (diff) | |
| download | rust-b73e613e008fd4a07a52ec7cef7c3af7db716b3d.tar.gz rust-b73e613e008fd4a07a52ec7cef7c3af7db716b3d.zip | |
De-duplicate and move `adjust_nan` to `InterpCx`
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret/cast.rs')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/cast.rs | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs index 30b5a8d70bc..1def3d08328 100644 --- a/compiler/rustc_const_eval/src/interpret/cast.rs +++ b/compiler/rustc_const_eval/src/interpret/cast.rs @@ -334,19 +334,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { { use rustc_type_ir::TyKind::*; - fn adjust_nan< - 'tcx, - M: Machine<'tcx>, - F1: rustc_apfloat::Float + FloatConvert<F2>, - F2: rustc_apfloat::Float, - >( - ecx: &InterpCx<'tcx, M>, - f1: F1, - f2: F2, - ) -> F2 { - if f2.is_nan() { M::generate_nan(ecx, &[f1]) } else { f2 } - } - match *dest_ty.kind() { // float -> uint Uint(t) => { @@ -367,11 +354,17 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { } // float -> float Float(fty) => match fty { - FloatTy::F16 => Scalar::from_f16(adjust_nan(self, f, f.convert(&mut false).value)), - FloatTy::F32 => Scalar::from_f32(adjust_nan(self, f, f.convert(&mut false).value)), - FloatTy::F64 => Scalar::from_f64(adjust_nan(self, f, f.convert(&mut false).value)), + FloatTy::F16 => { + Scalar::from_f16(self.adjust_nan(f.convert(&mut false).value, &[f])) + } + FloatTy::F32 => { + Scalar::from_f32(self.adjust_nan(f.convert(&mut false).value, &[f])) + } + FloatTy::F64 => { + Scalar::from_f64(self.adjust_nan(f.convert(&mut false).value, &[f])) + } FloatTy::F128 => { - Scalar::from_f128(adjust_nan(self, f, f.convert(&mut false).value)) + Scalar::from_f128(self.adjust_nan(f.convert(&mut false).value, &[f])) } }, // That's it. |
