about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTrevor Gross <tmgross@umich.edu>2024-06-13 08:29:38 -0500
committerTrevor Gross <tmgross@umich.edu>2024-06-14 12:43:58 -0500
commiteab5e8e9d95439adb4b63cd631dd24dae90cd9ad (patch)
treea6cdd8b986821954ea6bd2f1a897bc3649dca0ef
parentc906d2e428b9d20d1d73ec587bff75a6d25efed7 (diff)
downloadrust-eab5e8e9d95439adb4b63cd631dd24dae90cd9ad.tar.gz
rust-eab5e8e9d95439adb4b63cd631dd24dae90cd9ad.zip
Make the unary operator `FloatTy` check exhaustive
Add a spot that was missed in
<https://github.com/rust-lang/rust/pull/121997>.
-rw-r--r--compiler/rustc_const_eval/src/interpret/operator.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/operator.rs b/compiler/rustc_const_eval/src/interpret/operator.rs
index a6924371632..2175f051a19 100644
--- a/compiler/rustc_const_eval/src/interpret/operator.rs
+++ b/compiler/rustc_const_eval/src/interpret/operator.rs
@@ -433,13 +433,16 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
             }
             ty::Float(fty) => {
                 let val = val.to_scalar();
+                if un_op != Neg {
+                    span_bug!(self.cur_span(), "Invalid float op {:?}", un_op);
+                }
+
                 // No NaN adjustment here, `-` is a bitwise operation!
-                let res = match (un_op, fty) {
-                    (Neg, FloatTy::F16) => Scalar::from_f16(-val.to_f16()?),
-                    (Neg, FloatTy::F32) => Scalar::from_f32(-val.to_f32()?),
-                    (Neg, FloatTy::F64) => Scalar::from_f64(-val.to_f64()?),
-                    (Neg, FloatTy::F128) => Scalar::from_f128(-val.to_f128()?),
-                    _ => span_bug!(self.cur_span(), "Invalid float op {:?}", un_op),
+                let res = match fty {
+                    FloatTy::F16 => Scalar::from_f16(-val.to_f16()?),
+                    FloatTy::F32 => Scalar::from_f32(-val.to_f32()?),
+                    FloatTy::F64 => Scalar::from_f64(-val.to_f64()?),
+                    FloatTy::F128 => Scalar::from_f128(-val.to_f128()?),
                 };
                 Ok(ImmTy::from_scalar(res, layout))
             }