From b67635fdfd61d597f0145251dbe4ccb9c2487b8e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 9 Jun 2022 09:27:12 +1000 Subject: [PATCH] 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`. --- .../src/thir/pattern/deconstruct_pat.rs | 11 +---------- compiler/rustc_mir_build/src/thir/pattern/mod.rs | 6 +----- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs index 26532ae33d0..d97da1c8e1d 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs @@ -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), diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index 3161d95fff8..1029d0903c7 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -755,16 +755,12 @@ pub(crate) fn compare_const_vals<'tcx>( ty: Ty<'tcx>, ) -> Option { 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); }