rust: static_assert: add optional message
PATCH v4 1/1 rust: static_assert: add optional message
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.
---
Link to v3: https://lore.kernel.org/rust-for-linux/[email protected]/
--- rust/kernel/static_assert.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
rust/kernel/static_assert.rs +7 -2
@@ -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
Signature · 1 line
2.48.1
Hello Miguel,
Patch has been reviewed by Benno Lossin, can you check when you have time ?
Signature · 2 lines
Kind regards, Altan
Quoted 2 lines · Altan Ozlu
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
Quoted 2 lines
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!
Signature · 2 lines
Kind regards, Altan
Quoted 8 lines · 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.
I think this could be "Closes:"
Quoted 7 lines
Signed-off-by Altan Ozlu <[email protected]>---
Link to v3: https://lore.kernel.org/rust-for-linux/[email protected]/--- rust/kernel/static_assert.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
Quoted 2 lines · Trevor Gross
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
Miguel Ojeda
AppliedQuoted 9 lines · 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 <[email protected]>Signed-off-by Altan Ozlu <[email protected]>
Applied to rust-next -- thanks everyone!
Cheers,
Miguel