From: Younes Akhouayri <git@younes.io>
To: Rust For Linux <rust-for-linux@vger.kernel.org>
Cc: Acourbot <acourbot@nvidia.com>, Yury Norov <yury.norov@gmail.com>,
Ojeda <ojeda@kernel.org>,
Yu Whisper Personal <yu.whisper.personal@gmail.com>,
Git <git@younes.io>
Subject: From<bool> and Bounded's invariant for signed N = 1
Date: Thu, 13 Aug 2026 11:46:32 +0200 (CEST) [thread overview]
Message-ID: <OzuVxu0--J-9@younes.io> (raw)
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?
Thanks,
Younes
next reply other threads:[~2026-08-13 9:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 9:46 Younes Akhouayri [this message]
2026-08-13 10:16 ` From<bool> and Bounded's invariant for signed N = 1 Miguel Ojeda
2026-08-13 13:04 ` Alexandre Courbot
2026-08-13 19:52 ` Younes Akhouayri
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=OzuVxu0--J-9@younes.io \
--to=git@younes.io \
--cc=acourbot@nvidia.com \
--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.