rust: macros: Replace match + panic in const context with const expect
PATCH 1/1 rust: macros: Replace match + panic in const context with const expect
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).
---
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(-)
rust/kernel/error.rs +2 -4
@@ -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!`" ); }; }
Signature · 1 line
2.53.0
Quoted 7 lines · 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 <[email protected]>Suggested-by Gary Guo <[email protected]>
Miguel Ojeda
AppliedQuoted 8 lines · 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 <[email protected]>Suggested-by Gary Guo <[email protected]>
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
Quoted 3 lines · Miguel Ojeda
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.
Quoted 1 line
By the way,
scripts/checkpatch.plcan help you catch nits like that :)
Will use it next time! Thanks for the tip.
Cheers,
Daniel