[PATCH] rust: macros: Replace match + panic in const context with const expect

From: CastilloDel

Date: Wed Apr 08 2026 - 16:16:57 EST


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@xxxxxxxxx>
Suggested-by: Gary Guo <gary@xxxxxxxxxxx>
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