rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] rust: static_assert: add optional message
@ 2025-03-26 20:25 Altan Ozlu
  2025-04-15 19:26 ` Altan Ozlu
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Altan Ozlu @ 2025-03-26 20:25 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	rust-for-linux, Altan Ozlu

Add an optional panic message to the `static_assert!` macro.

The panic message doesn't support argument formatting, because the
`assert!` macro only supports formatting in non-const contexts.

Suggested-by: Miguel Ojeda <ojeda@kernel.org>
Link: https://github.com/Rust-for-Linux/linux/issues/1149
Signed-off-by: Altan Ozlu <altan@ozlu.eu>

---
Link to v3: https://lore.kernel.org/rust-for-linux/20250325211011.1093374-2-altan@ozlu.eu/
---
 rust/kernel/static_assert.rs | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/rust/kernel/static_assert.rs b/rust/kernel/static_assert.rs
index 3115ee0ba8e9..d8120f838260 100644
--- a/rust/kernel/static_assert.rs
+++ b/rust/kernel/static_assert.rs
@@ -6,6 +6,10 @@
 ///
 /// Similar to C11 [`_Static_assert`] and C++11 [`static_assert`].
 ///
+/// An optional panic message can be supplied after the expression.
+/// Currently only a string literal without formatting is supported
+/// due to constness limitations of the [`assert!`] macro.
+///
 /// The feature may be added to Rust in the future: see [RFC 2790].
 ///
 /// [`_Static_assert`]: https://en.cppreference.com/w/c/language/_Static_assert
@@ -25,10 +29,11 @@
 ///     x + 2
 /// }
 /// static_assert!(f(40) == 42);
+/// static_assert!(f(40) == 42, "f(x) must add 2 to the given input.");
 /// ```
 #[macro_export]
 macro_rules! static_assert {
-    ($condition:expr) => {
-        const _: () = core::assert!($condition);
+    ($condition:expr $(,$arg:literal)?) => {
+        const _: () = core::assert!($condition $(,$arg)?);
     };
 }

base-commit: a0b539ad369fe434fe488faf92d4ae770a27a90f
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v4] rust: static_assert: add optional message
@ 2025-03-27 22:41 Benno Lossin
  0 siblings, 0 replies; 8+ messages in thread
From: Benno Lossin @ 2025-03-27 22:41 UTC (permalink / raw)
  To: Altan Ozlu, Miguel Ojeda, Alex Gaynor
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Danilo Krummrich, rust-for-linux

On Wed Mar 26, 2025 at 9:25 PM CET, Altan Ozlu wrote:
> Add an optional panic message to the `static_assert!` macro.
>
> The panic message doesn't support argument formatting, because the
> `assert!` macro only supports formatting in non-const contexts.
>
> Suggested-by: Miguel Ojeda <ojeda@kernel.org>
> Link: https://github.com/Rust-for-Linux/linux/issues/1149
> Signed-off-by: Altan Ozlu <altan@ozlu.eu>

Reviewed-by: Benno Lossin <benno.lossin@proton.me>

---
Cheers,
Benno

> ---
> Link to v3: https://lore.kernel.org/rust-for-linux/20250325211011.1093374-2-altan@ozlu.eu/
> ---
>  rust/kernel/static_assert.rs | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4] rust: static_assert: add optional message
  2025-03-26 20:25 [PATCH v4] rust: static_assert: add optional message Altan Ozlu
@ 2025-04-15 19:26 ` Altan Ozlu
  2025-04-15 19:30   ` Miguel Ojeda
  2025-04-17  7:42 ` Trevor Gross
  2025-05-12 13:48 ` Miguel Ojeda
  2 siblings, 1 reply; 8+ messages in thread
From: Altan Ozlu @ 2025-04-15 19:26 UTC (permalink / raw)
  To: ojeda
  Cc: a.hindborg, alex.gaynor, aliceryhl, benno.lossin, bjorn3_gh,
	boqun.feng, dakr, gary, rust-for-linux, tmgross

Hello Miguel,

Patch has been reviewed by Benno Lossin, can you check when you have time ?

-- 
Kind regards,
Altan



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4] rust: static_assert: add optional message
  2025-04-15 19:26 ` Altan Ozlu
@ 2025-04-15 19:30   ` Miguel Ojeda
  2025-04-15 20:17     ` Altan Ozlu
  0 siblings, 1 reply; 8+ messages in thread
From: Miguel Ojeda @ 2025-04-15 19:30 UTC (permalink / raw)
  To: Altan Ozlu
  Cc: ojeda, a.hindborg, alex.gaynor, aliceryhl, benno.lossin,
	bjorn3_gh, boqun.feng, dakr, gary, rust-for-linux, tmgross

On Tue, Apr 15, 2025 at 9:26 PM Altan Ozlu <altan@ozlu.eu> wrote:
>
> Patch has been reviewed by Benno Lossin, can you check when you have time ?

If you mean applying it, I have not picked any patch for the next cycle yet.

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4] rust: static_assert: add optional message
  2025-04-15 19:30   ` Miguel Ojeda
@ 2025-04-15 20:17     ` Altan Ozlu
  0 siblings, 0 replies; 8+ messages in thread
From: Altan Ozlu @ 2025-04-15 20:17 UTC (permalink / raw)
  To: miguel.ojeda.sandonis
  Cc: a.hindborg, alex.gaynor, aliceryhl, altan, benno.lossin,
	bjorn3_gh, boqun.feng, dakr, gary, ojeda, rust-for-linux, tmgross

> 
> If you mean applying it, I have not picked any patch for the next cycle yet.

Yes I meant applying, I didn't knew about it. Thanks, have a nice day!
-- 
Kind regards,
Altan


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4] rust: static_assert: add optional message
  2025-03-26 20:25 [PATCH v4] rust: static_assert: add optional message Altan Ozlu
  2025-04-15 19:26 ` Altan Ozlu
@ 2025-04-17  7:42 ` Trevor Gross
  2025-04-17 10:53   ` Miguel Ojeda
  2025-05-12 13:48 ` Miguel Ojeda
  2 siblings, 1 reply; 8+ messages in thread
From: Trevor Gross @ 2025-04-17  7:42 UTC (permalink / raw)
  To: Altan Ozlu
  Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Danilo Krummrich, rust-for-linux

On Wed, Mar 26, 2025 at 3:25 PM Altan Ozlu <altan@ozlu.eu> wrote:
>
> Add an optional panic message to the `static_assert!` macro.
>
> The panic message doesn't support argument formatting, because the
> `assert!` macro only supports formatting in non-const contexts.
>
> Suggested-by: Miguel Ojeda <ojeda@kernel.org>
> Link: https://github.com/Rust-for-Linux/linux/issues/1149

I think this could be "Closes:"

> Signed-off-by: Altan Ozlu <altan@ozlu.eu>
>
> ---
> Link to v3: https://lore.kernel.org/rust-for-linux/20250325211011.1093374-2-altan@ozlu.eu/
> ---
>  rust/kernel/static_assert.rs | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)

Reviewed-by: Trevor Gross <tmgross@umich.edu>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4] rust: static_assert: add optional message
  2025-04-17  7:42 ` Trevor Gross
@ 2025-04-17 10:53   ` Miguel Ojeda
  0 siblings, 0 replies; 8+ messages in thread
From: Miguel Ojeda @ 2025-04-17 10:53 UTC (permalink / raw)
  To: Trevor Gross
  Cc: Altan Ozlu, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Danilo Krummrich, rust-for-linux

On Thu, Apr 17, 2025 at 9:42 AM Trevor Gross <tmgross@umich.edu> wrote:
>
> I think this could be "Closes:"

The documentation isn't very clear about it -- my reading is that
Closes is meant for bugs, so I have always used Link for feature
suggestions, but it would be reasonable to use it for that too like in
other trackers.

Thanks for reviewing!

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4] rust: static_assert: add optional message
  2025-03-26 20:25 [PATCH v4] rust: static_assert: add optional message Altan Ozlu
  2025-04-15 19:26 ` Altan Ozlu
  2025-04-17  7:42 ` Trevor Gross
@ 2025-05-12 13:48 ` Miguel Ojeda
  2 siblings, 0 replies; 8+ messages in thread
From: Miguel Ojeda @ 2025-05-12 13:48 UTC (permalink / raw)
  To: Altan Ozlu
  Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, rust-for-linux

On Wed, Mar 26, 2025 at 9:25 PM Altan Ozlu <altan@ozlu.eu> wrote:
>
> Add an optional panic message to the `static_assert!` macro.
>
> The panic message doesn't support argument formatting, because the
> `assert!` macro only supports formatting in non-const contexts.
>
> Suggested-by: Miguel Ojeda <ojeda@kernel.org>
> Link: https://github.com/Rust-for-Linux/linux/issues/1149
> Signed-off-by: Altan Ozlu <altan@ozlu.eu>

Applied to `rust-next` -- thanks everyone!

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-05-12 13:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-26 20:25 [PATCH v4] rust: static_assert: add optional message Altan Ozlu
2025-04-15 19:26 ` Altan Ozlu
2025-04-15 19:30   ` Miguel Ojeda
2025-04-15 20:17     ` Altan Ozlu
2025-04-17  7:42 ` Trevor Gross
2025-04-17 10:53   ` Miguel Ojeda
2025-05-12 13:48 ` Miguel Ojeda
  -- strict thread matches above, loose matches on Subject: below --
2025-03-27 22:41 Benno Lossin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).