Skip to content

Commit 50a4ca6

Browse files
committed
Make the unary operator FloatTy check exhaustive
Add a spot that was missed in <#121997>.
1 parent c9b7806 commit 50a4ca6

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

compiler/rustc_const_eval/src/interpret/operator.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,16 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
433433
}
434434
ty::Float(fty) => {
435435
let val = val.to_scalar();
436+
if un_op != Neg {
437+
span_bug!(self.cur_span(), "Invalid float op {:?}", un_op);
438+
}
439+
436440
// No NaN adjustment here, `-` is a bitwise operation!
437-
let res = match (un_op, fty) {
438-
(Neg, FloatTy::F16) => Scalar::from_f16(-val.to_f16()?),
439-
(Neg, FloatTy::F32) => Scalar::from_f32(-val.to_f32()?),
440-
(Neg, FloatTy::F64) => Scalar::from_f64(-val.to_f64()?),
441-
(Neg, FloatTy::F128) => Scalar::from_f128(-val.to_f128()?),
442-
_ => span_bug!(self.cur_span(), "Invalid float op {:?}", un_op),
441+
let res = match fty {
442+
FloatTy::F16 => Scalar::from_f16(-val.to_f16()?),
443+
FloatTy::F32 => Scalar::from_f32(-val.to_f32()?),
444+
FloatTy::F64 => Scalar::from_f64(-val.to_f64()?),
445+
FloatTy::F128 => Scalar::from_f128(-val.to_f128()?),
443446
};
444447
Ok(ImmTy::from_scalar(res, layout))
445448
}

0 commit comments

Comments
 (0)