mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-20 03:32:52 +00:00
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```
This commit is contained in:
commit
092f4600bb
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user