Skip to content

Commit

Permalink
avoid assertion failures in try_to_scalar_int
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Jul 30, 2022
1 parent 038f9e6 commit 848f301
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/mir/interpret/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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()
}
Expand All @@ -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()
}
Expand Down

0 comments on commit 848f301

Please sign in to comment.