Remove one use of compare_const_vals.

A direct comparison has the same effect. This also avoids the need for a
type test within `compare_const_vals`.
This commit is contained in:
Nicholas Nethercote 2022-06-09 09:27:12 +10:00
parent 9b4b34a0a6
commit b67635fdfd
2 changed files with 2 additions and 15 deletions

View file

@ -848,16 +848,7 @@ impl<'tcx> Constructor<'tcx> {
(Str(self_val), Str(other_val)) => {
// FIXME Once valtrees are available we can directly use the bytes
// in the `Str` variant of the valtree for the comparison here.
match compare_const_vals(
pcx.cx.tcx,
*self_val,
*other_val,
pcx.cx.param_env,
pcx.ty,
) {
Some(comparison) => comparison == Ordering::Equal,
None => false,
}
self_val == other_val
}
(Slice(self_slice), Slice(other_slice)) => self_slice.is_covered_by(*other_slice),

View file

@ -755,16 +755,12 @@ pub(crate) fn compare_const_vals<'tcx>(
ty: Ty<'tcx>,
) -> Option<Ordering> {
assert_eq!(a.ty(), b.ty());
assert_eq!(a.ty(), ty);
let from_bool = |v: bool| v.then_some(Ordering::Equal);
let fallback = || from_bool(a == b);
// Use the fallback if any type differs
if a.ty() != ty {
return fallback();
}
if a == b {
return from_bool(true);
}