Skip to content

Commit 092f460

Browse files
authored
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```
2 parents 370bf15 + 848f301 commit 092f460

File tree

1 file changed

+3
-1
lines changed
  • compiler/rustc_middle/src/mir/interpret

1 file changed

+3
-1
lines changed

compiler/rustc_middle/src/mir/interpret/value.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'tcx> ConstValue<'tcx> {
7979
}
8080

8181
pub fn try_to_scalar_int(&self) -> Option<ScalarInt> {
82-
Some(self.try_to_scalar()?.assert_int())
82+
self.try_to_scalar()?.try_to_int().ok()
8383
}
8484

8585
pub fn try_to_bits(&self, size: Size) -> Option<u128> {
@@ -368,6 +368,7 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> {
368368
}
369369

370370
#[inline(always)]
371+
#[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980)
371372
pub fn assert_int(self) -> ScalarInt {
372373
self.try_to_int().unwrap()
373374
}
@@ -389,6 +390,7 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> {
389390
}
390391

391392
#[inline(always)]
393+
#[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980)
392394
pub fn assert_bits(self, target_size: Size) -> u128 {
393395
self.to_bits(target_size).unwrap()
394396
}

0 commit comments

Comments
 (0)