public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: CastilloDel <delcastillodelarosadaniel@gmail.com>
To: "Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	CastilloDel <delcastillodelarosadaniel@gmail.com>
Subject: [PATCH] rust: macros: Replace match + panic in const context with const expect
Date: Wed,  8 Apr 2026 22:09:39 +0200	[thread overview]
Message-ID: <20260408200949.99059-1-delcastillodelarosadaniel@gmail.com> (raw)

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


             reply	other threads:[~2026-04-08 20:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-08 20:09 CastilloDel [this message]
2026-04-09  7:13 ` [PATCH] rust: macros: Replace match + panic in const context with const expect Alice Ryhl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260408200949.99059-1-delcastillodelarosadaniel@gmail.com \
    --to=delcastillodelarosadaniel@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox