rust/kernel/error.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
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
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
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
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>
© 2016 - 2026 Red Hat, Inc.