Re: [PATCH V2 1/2] rust: cpu: Introduce CpuId abstraction
From: Viresh Kumar
Date: Tue Jun 10 2025 - 06:19:08 EST
On 10-06-25, 11:43, Miguel Ojeda wrote:
> (By the way, as far as I understand there is no way we could wrap
> going to `i32`, but it may not hurt to add a `debug_assert!` in the
> `u32` constructors.)
Something like this ?
@@ -79,6 +79,7 @@ pub fn from_i32(id: i32) -> Option<Self> {
#[inline]
pub unsafe fn from_u32_unchecked(id: u32) -> Self {
debug_assert!(id < nr_cpu_ids());
+ debug_assert!(id <= i32::MAX as u32);
// INVARIANT: The function safety guarantees `id` is a valid CPU id.
Self(id)
--
viresh