mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
use strict_ instead of checked_ in a few more places
This commit is contained in:
parent
654ad5230a
commit
c0fe47d671
@ -45,7 +45,7 @@ macro_rules! declare_id {
|
||||
// We use 0 as a sentinel value (see the comment above) and,
|
||||
// therefore, need to shift by one when converting from an index
|
||||
// into a vector.
|
||||
let shifted_idx = u32::try_from(idx).unwrap().checked_add(1).unwrap();
|
||||
let shifted_idx = u32::try_from(idx).unwrap().strict_add(1);
|
||||
$name(std::num::NonZero::new(shifted_idx).unwrap())
|
||||
}
|
||||
fn index(self) -> usize {
|
||||
@ -350,7 +350,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
} else {
|
||||
mutex.owner = Some(thread);
|
||||
}
|
||||
mutex.lock_count = mutex.lock_count.checked_add(1).unwrap();
|
||||
mutex.lock_count = mutex.lock_count.strict_add(1);
|
||||
if let Some(data_race) = &this.machine.data_race {
|
||||
data_race.acquire_clock(&mutex.clock, &this.machine.threads);
|
||||
}
|
||||
@ -370,9 +370,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
return Ok(None);
|
||||
}
|
||||
let old_lock_count = mutex.lock_count;
|
||||
mutex.lock_count = old_lock_count
|
||||
.checked_sub(1)
|
||||
.expect("invariant violation: lock_count == 0 iff the thread is unlocked");
|
||||
mutex.lock_count = old_lock_count.strict_sub(1);
|
||||
if mutex.lock_count == 0 {
|
||||
mutex.owner = None;
|
||||
// The mutex is completely unlocked. Try transferring ownership
|
||||
@ -450,7 +448,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
trace!("rwlock_reader_lock: {:?} now also held (one more time) by {:?}", id, thread);
|
||||
let rwlock = &mut this.machine.sync.rwlocks[id];
|
||||
let count = rwlock.readers.entry(thread).or_insert(0);
|
||||
*count = count.checked_add(1).expect("the reader counter overflowed");
|
||||
*count = count.strict_add(1);
|
||||
if let Some(data_race) = &this.machine.data_race {
|
||||
data_race.acquire_clock(&rwlock.clock_unlocked, &this.machine.threads);
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
os_str: &OsStr,
|
||||
memkind: MemoryKind,
|
||||
) -> InterpResult<'tcx, Pointer> {
|
||||
let size = u64::try_from(os_str.len()).unwrap().checked_add(1).unwrap(); // Make space for `0` terminator.
|
||||
let size = u64::try_from(os_str.len()).unwrap().strict_add(1); // Make space for `0` terminator.
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let arg_type = Ty::new_array(this.tcx.tcx, this.tcx.types.u8, size);
|
||||
@ -158,7 +158,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
os_str: &OsStr,
|
||||
memkind: MemoryKind,
|
||||
) -> InterpResult<'tcx, Pointer> {
|
||||
let size = u64::try_from(os_str.len()).unwrap().checked_add(1).unwrap(); // Make space for `0x0000` terminator.
|
||||
let size = u64::try_from(os_str.len()).unwrap().strict_add(1); // Make space for `0x0000` terminator.
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let arg_type = Ty::new_array(this.tcx.tcx, this.tcx.types.u16, size);
|
||||
|
@ -893,7 +893,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
|
||||
let dirent64_layout = this.libc_ty_layout("dirent64");
|
||||
let d_name_offset = dirent64_layout.fields.offset(4 /* d_name */).bytes();
|
||||
let size = d_name_offset.checked_add(name_len).unwrap();
|
||||
let size = d_name_offset.strict_add(name_len);
|
||||
|
||||
let entry = this.allocate_ptr(
|
||||
Size::from_bytes(size),
|
||||
@ -994,7 +994,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
name_place.ptr(),
|
||||
name_place.layout.size.bytes(),
|
||||
)?;
|
||||
let file_name_len = file_name_buf_len.checked_sub(1).unwrap();
|
||||
let file_name_len = file_name_buf_len.strict_sub(1);
|
||||
if !name_fits {
|
||||
throw_unsup_format!(
|
||||
"a directory entry had a name too large to fit in libc::dirent"
|
||||
|
@ -176,8 +176,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
// of 4.
|
||||
let chunk_base = i & !0b11;
|
||||
let src_i = u64::from(this.read_scalar(&control)?.to_u32()? & 0b11)
|
||||
.checked_add(chunk_base)
|
||||
.unwrap();
|
||||
.strict_add(chunk_base);
|
||||
|
||||
this.copy_op(
|
||||
&this.project_index(&data, src_i)?,
|
||||
@ -210,9 +209,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
// second instead of the first, ask Intel). To read the value from the current
|
||||
// chunk, add the destination index truncated to a multiple of 2.
|
||||
let chunk_base = i & !1;
|
||||
let src_i = ((this.read_scalar(&control)?.to_u64()? >> 1) & 1)
|
||||
.checked_add(chunk_base)
|
||||
.unwrap();
|
||||
let src_i =
|
||||
((this.read_scalar(&control)?.to_u64()? >> 1) & 1).strict_add(chunk_base);
|
||||
|
||||
this.copy_op(
|
||||
&this.project_index(&data, src_i)?,
|
||||
|
Loading…
Reference in New Issue
Block a user