about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-08-18 05:10:42 +0200
committerGitHub <noreply@github.com>2022-08-18 05:10:42 +0200
commit092f4600bb3c83e52db3c1a777afb26d0b84b80f (patch)
treee8517d1b54c89a7a749011d2347360c43e6af239
parent370bf1543dc1033194403241fbb73d3b8c1d48b3 (diff)
parent848f301782f1dc2e40241e503711fd6e11aefebe (diff)
downloadrust-092f4600bb3c83e52db3c1a777afb26d0b84b80f.tar.gz
rust-092f4600bb3c83e52db3c1a777afb26d0b84b80f.zip
Rollup merge of #99966 - RalfJung:try-dont-panic, r=lcnr
avoid assertion failures in try_to_scalar_int

Given that this is called `try_to_scalar_int`, we probably shouldn't `assert_int` here. Similarly `try_to_bits` also doesn't `assert!` that the size is correct.

Also add some `track_caller` for debugging, while we are at it.

r? ```@oli-obk```
-rw-r--r--compiler/rustc_middle/src/mir/interpret/value.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/mir/interpret/value.rs b/compiler/rustc_middle/src/mir/interpret/value.rs
index 834c114ee1c..a1c111ae372 100644
--- a/compiler/rustc_middle/src/mir/interpret/value.rs
+++ b/compiler/rustc_middle/src/mir/interpret/value.rs
@@ -79,7 +79,7 @@ impl<'tcx> ConstValue<'tcx> {
     }
 
     pub fn try_to_scalar_int(&self) -> Option<ScalarInt> {
-        Some(self.try_to_scalar()?.assert_int())
+        self.try_to_scalar()?.try_to_int().ok()
     }
 
     pub fn try_to_bits(&self, size: Size) -> Option<u128> {
@@ -368,6 +368,7 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> {
     }
 
     #[inline(always)]
+    #[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980)
     pub fn assert_int(self) -> ScalarInt {
         self.try_to_int().unwrap()
     }
@@ -389,6 +390,7 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> {
     }
 
     #[inline(always)]
+    #[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980)
     pub fn assert_bits(self, target_size: Size) -> u128 {
         self.to_bits(target_size).unwrap()
     }