From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Younes Akhouayri" <git@younes.io>
Cc: "Rust For Linux" <rust-for-linux@vger.kernel.org>,
"Yury Norov" <yury.norov@gmail.com>, "Ojeda" <ojeda@kernel.org>,
"Yu Whisper Personal" <yu.whisper.personal@gmail.com>
Subject: Re: From<bool> and Bounded's invariant for signed N = 1
Date: Thu, 13 Aug 2026 22:04:22 +0900 [thread overview]
Message-ID: <DKNU5IBDCA44.28C93KM4IQS44@nvidia.com> (raw)
In-Reply-To: <OzuVxu0--J-9@younes.io>
On Thu Aug 13, 2026 at 6:46 PM JST, Younes Akhouayri wrote:
> Hi,
>
> There seems to be an invariant violation in the generic From<bool>
> implementation for Bounded.
>
> As I understand it, Bounded<i8, 1> can represent only -1 and 0, while
> i8::from(true) produces 1. However, this safe code is accepted:
>
> let value: Bounded<i8, 1> = true.into();
> let _raw: i8 = *value;
>
> Bounded::<i8, 1>::try_new(1) rejects the same value, but From<bool>
> passes it directly to the unsafe __new() constructor. The resulting
> Bounded value violates the invariant relied upon by Deref, whose
> failure branch calls unreachable_unchecked().
>
> Am I missing an intended constraint on this conversion? If not, it
> seems the signed N = 1 case needs to be excluded or handled
> differently.
>
> Any thoughts?
I think you are correct. There is a `Signedness` associated type on the
`Integer` trait, so it should be trivial to exclude signed integers - do
you want to send a patch for that?
prev parent reply other threads:[~2026-08-13 13:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 9:46 From<bool> and Bounded's invariant for signed N = 1 Younes Akhouayri
2026-08-13 10:16 ` Miguel Ojeda
2026-08-13 13:04 ` Alexandre Courbot [this message]
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=DKNU5IBDCA44.28C93KM4IQS44@nvidia.com \
--to=acourbot@nvidia.com \
--cc=git@younes.io \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=yu.whisper.personal@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.