public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yury Norov <yury.norov@gmail.com>
To: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Cc: "Alexandre Courbot" <acourbot@nvidia.com>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Joel Fernandes" <joelagnelf@nvidia.com>,
	"Jesung Yang" <y.j3ms.n@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH 1/2] rust: add BitInt integer wrapping type
Date: Mon, 3 Nov 2025 14:43:03 -0500	[thread overview]
Message-ID: <aQkFx-brq-_njd5D@yury> (raw)
In-Reply-To: <CANiq72=4UXemR3ea5nNbqGt0Zh9q4hwiGVAn+hxfcZ-Zqa8y4w@mail.gmail.com>

On Mon, Nov 03, 2025 at 03:54:08PM +0100, Miguel Ojeda wrote:
> On Mon, Nov 3, 2025 at 3:26 PM Yury Norov <yury.norov@gmail.com> wrote:
> >
> > This is exactly what the patch does:
> 
> No, there are no arithmetic conversions going on here in the sense of
> C. It defines a particular operation for a set of types.
> 
> What you are seeing there is that literals, in Rust, do type
> inference, and so the compiler picks a type:
> 
>     https://doc.rust-lang.org/reference/expressions/literal-expr.html#r-expr.literal.int.infer
> 
> Thus if you do:
> 
>     let v1 = BitInt::<u8, 4>::from_expr(15);
>     let v2 = BitInt::<u16, 4>::from_expr(15);
>     let i = 5;
>     assert_eq!(v1 + i, 20);
>     assert_eq!(v2 + i, 20);
> 
> That will not build, because `i` cannot have two types. But it will if
> you comment one of the two asserts.
> 
> And if you do:
> 
>     let v = BitInt::<u16, 4>::from_expr(15);
>     assert_eq!(v + 5u8, 20);
> 
> It will not build either -- there is not even "widening" going on from
> `u8` to `u16` in this last example.

The current BitInt() allows this:

  let v = BitInt::<u32, 4>::new::<15>();
  assert_eq!(v * 10, 150);

It looks and feels like C integer promotion. If Rust doesn't like it,
we shouldn't allow such things with BitInt()s.

  reply	other threads:[~2025-11-03 19:43 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-31 13:39 [PATCH 0/2] rust: add BitInt type and use in Nova's bitfield macro Alexandre Courbot
2025-10-31 13:39 ` [PATCH 1/2] rust: add BitInt integer wrapping type Alexandre Courbot
2025-11-02  5:46   ` Alexandre Courbot
2025-11-03  2:17   ` Yury Norov
2025-11-03 10:47     ` Alice Ryhl
2025-11-03 14:31       ` Alexandre Courbot
2025-11-03 13:42     ` Alexandre Courbot
2025-11-03 13:57       ` Alexandre Courbot
2025-11-03 14:01         ` Danilo Krummrich
2025-11-03 19:36       ` Yury Norov
2025-11-04  3:13         ` Alexandre Courbot
2025-11-04 19:30           ` Yury Norov
2025-11-04 20:21             ` Danilo Krummrich
2025-11-05 14:03             ` Alexandre Courbot
2025-11-05 15:45               ` Yury Norov
2025-11-03 14:10     ` Miguel Ojeda
2025-11-03 14:26       ` Yury Norov
2025-11-03 14:44         ` Alexandre Courbot
2025-11-03 14:54         ` Miguel Ojeda
2025-11-03 19:43           ` Yury Norov [this message]
2025-11-03 20:00             ` Yury Norov
2025-10-31 13:39 ` [PATCH FOR REFERENCE 2/2] gpu: nova-core: use BitInt for bitfields 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=aQkFx-brq-_njd5D@yury \
    --to=yury.norov@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=joelagnelf@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=y.j3ms.n@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