* [PATCH] rust: macros: Replace match + panic in const context with const expect
@ 2026-04-08 20:09 CastilloDel
2026-04-09 7:13 ` Alice Ryhl
2026-05-28 9:17 ` Miguel Ojeda
0 siblings, 2 replies; 4+ messages in thread
From: CastilloDel @ 2026-04-08 20:09 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich
Cc: rust-for-linux, linux-kernel, CastilloDel
This patch replaces an instance of match + panic with const expect,
which is now usable in const contexts after the MSRV was was updated to
1.85.0 (it was available since Rust 1.83.0).
Signed-off-by: Daniel del Castillo <delcastillodelarosadaniel@gmail.com>
Suggested-by: Gary Guo <gary@garyguo.net>
Link: https://github.com/Rust-for-Linux/linux/issues/1229
---
I searched for other appearances, but couldn't find any. There is a
similar one in the `c_str!` macro in `rust/kernel/str.rs`, but it would
need `Result::expect` (or `Result::ok`) to be const. The original issue
will probably have to wait for those to be fully resolved.
---
rust/kernel/error.rs | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs
index decceb6ae855..2ef5226f3913 100644
--- a/rust/kernel/error.rs
+++ b/rust/kernel/error.rs
@@ -25,10 +25,8 @@ macro_rules! declare_err {
#[doc = $doc]
)*
pub const $err: super::Error =
- match super::Error::try_from_errno(-(crate::bindings::$err as i32)) {
- Some(err) => err,
- None => panic!("Invalid errno in `declare_err!`"),
- };
+ super::Error::try_from_errno(-(crate::bindings::$err as i32))
+ .expect("Invalid errno in `declare_err!`");
};
}
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: macros: Replace match + panic in const context with const expect
2026-04-08 20:09 [PATCH] rust: macros: Replace match + panic in const context with const expect CastilloDel
@ 2026-04-09 7:13 ` Alice Ryhl
2026-05-28 9:17 ` Miguel Ojeda
1 sibling, 0 replies; 4+ messages in thread
From: Alice Ryhl @ 2026-04-09 7:13 UTC (permalink / raw)
To: CastilloDel
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
rust-for-linux, linux-kernel
On Wed, Apr 08, 2026 at 10:09:39PM +0200, CastilloDel wrote:
> This patch replaces an instance of match + panic with const expect,
> which is now usable in const contexts after the MSRV was was updated to
> 1.85.0 (it was available since Rust 1.83.0).
>
> Signed-off-by: Daniel del Castillo <delcastillodelarosadaniel@gmail.com>
> Suggested-by: Gary Guo <gary@garyguo.net>
> Link: https://github.com/Rust-for-Linux/linux/issues/1229
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: macros: Replace match + panic in const context with const expect
2026-04-08 20:09 [PATCH] rust: macros: Replace match + panic in const context with const expect CastilloDel
2026-04-09 7:13 ` Alice Ryhl
@ 2026-05-28 9:17 ` Miguel Ojeda
2026-05-31 11:19 ` Daniel del Castillo
1 sibling, 1 reply; 4+ messages in thread
From: Miguel Ojeda @ 2026-05-28 9:17 UTC (permalink / raw)
To: CastilloDel
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, rust-for-linux, linux-kernel
On Wed, Apr 8, 2026 at 10:10 PM CastilloDel
<delcastillodelarosadaniel@gmail.com> wrote:
>
> This patch replaces an instance of match + panic with const expect,
> which is now usable in const contexts after the MSRV was was updated to
> 1.85.0 (it was available since Rust 1.83.0).
>
> Signed-off-by: Daniel del Castillo <delcastillodelarosadaniel@gmail.com>
> Suggested-by: Gary Guo <gary@garyguo.net>
> Link: https://github.com/Rust-for-Linux/linux/issues/1229
Applied to `rust-next` -- thanks!
[ Adjusted Git author's name with the Signed-off-by value. Reworded
slightly and removed duplicated word. - Miguel ]
Please shout if the author adjustment is not correct (and please check
your Git settings so that Git uses the right one when creating the
commit for the future).
By the way, `scripts/checkpatch.pl` can help you catch nits like that :)
Cheers,
Miguel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: macros: Replace match + panic in const context with const expect
2026-05-28 9:17 ` Miguel Ojeda
@ 2026-05-31 11:19 ` Daniel del Castillo
0 siblings, 0 replies; 4+ messages in thread
From: Daniel del Castillo @ 2026-05-31 11:19 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, rust-for-linux, linux-kernel
On 5/28/26 11:17, Miguel Ojeda wrote:
> Please shout if the author adjustment is not correct (and please check
> your Git settings so that Git uses the right one when creating the
> commit for the future).
That looks correct to me! Thanks for making it consistent.
> By the way, `scripts/checkpatch.pl` can help you catch nits like that :)
Will use it next time! Thanks for the tip.
Cheers,
Daniel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-05-31 11:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-08 20:09 [PATCH] rust: macros: Replace match + panic in const context with const expect CastilloDel
2026-04-09 7:13 ` Alice Ryhl
2026-05-28 9:17 ` Miguel Ojeda
2026-05-31 11:19 ` Daniel del Castillo
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.