[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CANiq72kQ4BPG+0b4aV4dEucv3K+45civWN7iRwX+qpON0TGSxQ@mail.gmail.com>
Date: Wed, 7 Jan 2026 22:38:35 +0100
From: Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
To: Hsiu Che Yu <yu.whisper.personal@...il.com>
Cc: Alexandre Courbot <acourbot@...dia.com>, Miguel Ojeda <ojeda@...nel.org>,
Yury Norov <yury.norov@...il.com>, Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <lossin@...nel.org>, Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3] rust: num: bounded: mark __new as unsafe
On Thu, Dec 4, 2025 at 4:39 AM Hsiu Che Yu
<yu.whisper.personal@...il.com> wrote:
>
> The `Bounded::__new()` constructor relies on the caller to ensure the
> value can be represented within N bits. Failing to uphold this
> requirement breaks the type invariant. Mark it as unsafe and document
> this requirement in a Safety section to make the contract explicit.
>
> Update all call sites to use unsafe blocks and change their comments
> from `INVARIANT:` to `SAFETY:`, as they are now justifying unsafe
> operations rather than establishing type invariants.
>
> Fixes: 01e345e82ec3a ("rust: num: add Bounded integer wrapping type")
> Link: https://lore.kernel.org/all/aS1qC_ol2XEpZ44b@google.com/
> Reported-by: Miguel Ojeda <ojeda@...nel.org>
> Closes: https://github.com/Rust-for-Linux/linux/issues/1211
> Signed-off-by: Hsiu Che Yu <yu.whisper.personal@...il.com>
Applied to `rust-fixes` -- thanks everyone!
We can do the cleanups I mentioned on top later, but let's get this part done.
Cheers,
Miguel
Powered by blists - more mailing lists