Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 73c52b7

Browse files
committed
compare_const_vals: Use infallible evaluation.
Because these evaluations can never fail.
1 parent 246a5e0 commit 73c52b7

File tree

1 file changed

+23
-27
lines changed
  • compiler/rustc_mir_build/src/thir/pattern

1 file changed

+23
-27
lines changed

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

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -760,32 +760,28 @@ pub(crate) fn compare_const_vals<'tcx>(
760760
}
761761

762762
let ty = a.ty();
763-
let a_bits = a.try_eval_bits(tcx, param_env, ty);
764-
let b_bits = b.try_eval_bits(tcx, param_env, ty);
765-
766-
if let (Some(a), Some(b)) = (a_bits, b_bits) {
767-
use rustc_apfloat::Float;
768-
return match *ty.kind() {
769-
ty::Float(ty::FloatTy::F32) => {
770-
let l = rustc_apfloat::ieee::Single::from_bits(a);
771-
let r = rustc_apfloat::ieee::Single::from_bits(b);
772-
l.partial_cmp(&r)
773-
}
774-
ty::Float(ty::FloatTy::F64) => {
775-
let l = rustc_apfloat::ieee::Double::from_bits(a);
776-
let r = rustc_apfloat::ieee::Double::from_bits(b);
777-
l.partial_cmp(&r)
778-
}
779-
ty::Int(ity) => {
780-
use rustc_middle::ty::layout::IntegerExt;
781-
let size = rustc_target::abi::Integer::from_int_ty(&tcx, ity).size();
782-
let a = size.sign_extend(a);
783-
let b = size.sign_extend(b);
784-
Some((a as i128).cmp(&(b as i128)))
785-
}
786-
_ => Some(a.cmp(&b)),
787-
};
763+
let a = a.eval_bits(tcx, param_env, ty);
764+
let b = b.eval_bits(tcx, param_env, ty);
765+
766+
use rustc_apfloat::Float;
767+
match *ty.kind() {
768+
ty::Float(ty::FloatTy::F32) => {
769+
let a = rustc_apfloat::ieee::Single::from_bits(a);
770+
let b = rustc_apfloat::ieee::Single::from_bits(b);
771+
a.partial_cmp(&b)
772+
}
773+
ty::Float(ty::FloatTy::F64) => {
774+
let a = rustc_apfloat::ieee::Double::from_bits(a);
775+
let b = rustc_apfloat::ieee::Double::from_bits(b);
776+
a.partial_cmp(&b)
777+
}
778+
ty::Int(ity) => {
779+
use rustc_middle::ty::layout::IntegerExt;
780+
let size = rustc_target::abi::Integer::from_int_ty(&tcx, ity).size();
781+
let a = size.sign_extend(a);
782+
let b = size.sign_extend(b);
783+
Some((a as i128).cmp(&(b as i128)))
784+
}
785+
_ => Some(a.cmp(&b)),
788786
}
789-
790-
None
791787
}

0 commit comments

Comments
 (0)