diff options
| author | Ralf Jung <post@ralfj.de> | 2025-07-29 17:22:22 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2025-08-14 09:44:22 +0200 |
| commit | e2cc7757e1bdbe8c9dc0dcffc1017ceff4799899 (patch) | |
| tree | 1164d3542a380408431653bb7a0c50ac55a96e83 /compiler/rustc_middle | |
| parent | dbc030e0346f0958bea91601de7d115554bbf74e (diff) | |
| download | rust-e2cc7757e1bdbe8c9dc0dcffc1017ceff4799899.tar.gz rust-e2cc7757e1bdbe8c9dc0dcffc1017ceff4799899.zip | |
avoid unnecessary type sanity checks
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/ty/consts/valtree.rs | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/compiler/rustc_middle/src/ty/consts/valtree.rs b/compiler/rustc_middle/src/ty/consts/valtree.rs index 0f6f3f0c0e2..bf20520f4cd 100644 --- a/compiler/rustc_middle/src/ty/consts/valtree.rs +++ b/compiler/rustc_middle/src/ty/consts/valtree.rs @@ -151,17 +151,13 @@ impl<'tcx> Value<'tcx> { /// or an aggregate). #[inline] pub fn try_to_bits(self, tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>) -> Option<u128> { - let scalar = self.try_to_scalar_int()?; - let input = typing_env.with_post_analysis_normalized(tcx).as_query_input(self.ty); - let size = tcx.layout_of(input).ok()?.size; - Some(scalar.to_bits(size)) - } - - pub fn try_to_scalar_int(self) -> Option<ScalarInt> { let (ty::Bool | ty::Char | ty::Uint(_) | ty::Int(_) | ty::Float(_)) = self.ty.kind() else { return None; }; - self.valtree.try_to_scalar_int() + let scalar = self.valtree.try_to_scalar_int()?; + let input = typing_env.with_post_analysis_normalized(tcx).as_query_input(self.ty); + let size = tcx.layout_of(input).ok()?.size; + Some(scalar.to_bits(size)) } pub fn try_to_bool(self) -> Option<bool> { |
