Skip to content

Commit 2c99de1

Browse files
committed
Avoid same-type casts in unsigned member conversion
On targets where c_ulong is u32, casting through c_ulong was a no-op cast that clippy rejects. Assisted-by: Claude:claude-opus-5-5
1 parent c5b9ffe commit 2c99de1

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎crates/vm/src/builtins/descriptor.rs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,14 +706,15 @@ fn member_uint_value(
706706
if big.sign() == malachite_bigint::Sign::Minus {
707707
let long_val = core::ffi::c_long::try_from(big)
708708
.map_err(|_| vm.new_overflow_error("Python int too large to convert to C long"))?;
709-
let stored = (long_val as core::ffi::c_ulong) as u32;
709+
// Keeps the low 32 bits whether `c_long` is 32 or 64 bits wide.
710+
let stored = long_val as u32;
710711
return Ok((stored, Some("Writing negative value into unsigned field")));
711712
}
712-
let ulong_val = core::ffi::c_ulong::try_from(big)
713+
core::ffi::c_ulong::try_from(big)
713714
.map_err(|_| vm.new_overflow_error("Python int too large to convert to C unsigned long"))?;
714-
let stored = ulong_val as u32;
715-
let warning = (ulong_val > u32::MAX as core::ffi::c_ulong)
716-
.then_some("Truncation of value to unsigned int");
715+
let wide = u64::try_from(big).expect("a value that fits c_ulong fits u64");
716+
let stored = wide as u32;
717+
let warning = (wide > u64::from(u32::MAX)).then_some("Truncation of value to unsigned int");
717718
Ok((stored, warning))
718719
}
719720

0 commit comments

Comments
 (0)