mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: git@younes.io, "Alexandre Courbot" <acourbot@nvidia.com>,
	"Yury Norov" <yury.norov@gmail.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Onur Özkan" <work@onurozkan.dev>
Cc: <rust-for-linux@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] rust: num: document why Integer is sealed
Date: Sun, 06 Sep 2026 13:46:18 +0100	[thread overview]
Message-ID: <DL88SQWYU15W.2CVZB5NVSSJGK@garyguo.net> (raw)
In-Reply-To: <20260906-docs-rust-num-integer-sealing-safety-v1-1-78057391302c@younes.io>

On Sun Sep 6, 2026 at 8:40 AM BST, Younes Akhouayri via B4 Relay wrote:
> From: Younes Akhouayri <git@younes.io>
>
> Bounded relies on Integer::BITS and Integer::Signedness accurately
> describing the implementing type to justify unchecked operations.
> The reason external implementations are prohibited is currently recorded
> only in the commit history.
>
> Document this safety requirement on Integer itself.
>
> Suggested-by: Miguel Ojeda <ojeda@kernel.org>
> Link: https://lore.kernel.org/all/CANiq72m8kycbfQ1teyne-OtB5d5TsUcX_WW0FCkWB3Ayyg-qWw@mail.gmail.com/
> Signed-off-by: Younes Akhouayri <git@younes.io>
> ---
>  rust/kernel/num.rs | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/rust/kernel/num.rs b/rust/kernel/num.rs
> index de589792a77a..1d06395d3a63 100644
> --- a/rust/kernel/num.rs
> +++ b/rust/kernel/num.rs
> @@ -20,6 +20,11 @@ pub trait Sealed {}
>  }
>  
>  /// Describes core properties of integer types.
> +///
> +/// This trait is sealed because [`Bounded`] relies on [`Integer::BITS`] and
> +/// [`Integer::Signedness`] accurately describing the implementing type to
> +/// justify unchecked operations. An incorrect implementation could therefore
> +/// make safe [`Bounded`] operations cause undefined behavior.

I think this is a fairly typical case where correctness turns into safety --
i.e. unsafe code depends on correct impl of safe code. I think a

    // sealed so that unsafe code can rely on correctness

could be sufficient. I imagine with a future sealed attribute, they can also be
single line, so

    #[sealed] // so that unsafe code can rely on correctnes

would serve the purpose. Miguel, any thoughts?

Best,
Gary

>  pub trait Integer:
>      private::Sealed
>      + Sized
>
> ---
> base-commit: c6709d5e14072d0e3d02f291daee46a199e5dad3
> change-id: 20260906-docs-rust-num-integer-sealing-safety-3a0e2967a948
>
> Best regards,
> --  
> Younes Akhouayri <git@younes.io>



  reply	other threads:[~2026-09-06 12:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-06  7:40 Younes Akhouayri via B4 Relay
2026-09-06 12:46 ` Gary Guo [this message]
2026-09-06 13:00   ` Miguel Ojeda
2026-09-06 15:25 ` Alexandre Courbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DL88SQWYU15W.2CVZB5NVSSJGK@garyguo.net \
    --to=gary@garyguo.net \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=git@younes.io \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    --cc=yury.norov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®