Skip to contentSkip to conversation

rust: pin-init: use irrefutable pattern for `stack_pin_init`

PATCH Applied Gary Guo 3 participants 5 messages Aug 28 – Sep 1

Subsystems (2)
lore
Share & tools
lore

Gary Guo

author
#0 lore raw

PATCH 1/1 rust: pin-init: use irrefutable pattern for `stack_pin_init`

From: Gary Guo <[email protected]>

In Rust 1.100.0, Infallible will become an alias of !. The let binding in stack_pin_init will thus become unreachable and produce a "unreachable expression" warning for subsequent match, and thus will fail -Dwarnings build. For this macro, all we need to know is that the error type is uninhabited, so replace this with a irrefutable pattern instead.

---
Miguel, given that we're very early in the cycle and this effect upcoming nightly compiler, I'd prefer to route this via rust-fixes instead of pin-init-next. Thanks.

---
 rust/pin-init/src/lib.rs | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
rust/pin-init/src/lib.rs +1 -7
index 7600cdbbbf98..f1463be9479d 100644
@@ -490,13 +490,7 @@ macro_rules! stack_pin_init {
     (let $var:ident $(: $t:ty)? = $val:expr) => {
         let val = $val;
         let mut $var = ::core::pin::pin!($crate::__internal::StackInit$(::<$t>)?::uninit());
-        let mut $var = match $crate::__internal::StackInit::init($var, val) {
-            Ok(res) => res,
-            Err(x) => {
-                let x: ::core::convert::Infallible = x;
-                match x {}
-            }
-        };
+        let Ok(mut $var) = $crate::__internal::StackInit::init($var, val);
     };
 }
 

base-commit: d8aa025c1cd5908eb454e48af031370f23d3c559

Signature · 1 line
2.54.0
#1 lore raw
Quoted 4 lines · Gary Guo

Miguel, given that we're very early in the cycle and this effect upcoming nightly compiler, I'd prefer to route this via rust-fixes instead of pin-init-next. Thanks.

Sounds good. I was about to send the PR to Linus, so I will put this one in the next round of fixes.

Cheers,
Miguel

Applied
#2 lore raw
In reply to Gary Guo
Quoted 9 lines · Gary Guo

From: Gary Guo <[email protected]>

In Rust 1.100.0, Infallible will become an alias of !. The let binding in stack_pin_init will thus become unreachable and produce a "unreachable expression" warning for subsequent match, and thus will fail -Dwarnings build. For this macro, all we need to know is that the error type is uninhabited, so replace this with a irrefutable pattern instead.

Quoted 3 lines

Applied to rust-fixes -- thanks!

For stable, we will need a custom backport without feature(min_exhaustive_patterns) (we could in principle enable that one since it is available in Rust 1.77.0, but for stable I would avoid it), so I wrote this tag:

Cc: [email protected] # Needed in 7.1.y and later (for 6.12.y
and 6.18.y a custom one is needed).

[ The error looks like (dummy reproducer):

error: unreachable expression
--> rust/kernel/sync.rs:177:5
|
177 | pin_init::stack_pin_init!(let num = 42u32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| unreachable expression
| any code following this expression is unreachable
|
= note: -D unreachable-code implied by -D warnings = help: to override -D warnings add #[allow(unreachable_code)] = note: this error originates in the macro
pin_init::stack_pin_init (in Nightly builds, run with -Z macro-backtrace for more info)

- Miguel ]

[ Reworded for typos. - Miguel ]

Cheers,
Miguel

maintainer
#3 lore raw
Quoted 14 lines · Miguel Ojeda
Quoted 9 lines · Gary Guo

From: Gary Guo <[email protected]>

In Rust 1.100.0, Infallible will become an alias of !. The let binding in stack_pin_init will thus become unreachable and produce a "unreachable expression" warning for subsequent match, and thus will fail -Dwarnings build. For this macro, all we need to know is that the error type is uninhabited, so replace this with a irrefutable pattern instead.

Quoted 3 lines
Quoted 6 lines

Applied to rust-fixes -- thanks!

For stable, we will need a custom backport without feature(min_exhaustive_patterns) (we could in principle enable that one since it is available in Rust 1.77.0, but for stable I would avoid it), so I wrote this tag:

We can probably just allow unreachable_code?

Best,
Gary

Quoted 27 lines

Cc: [email protected] # Needed in 7.1.y and later (for 6.12.y
and 6.18.y a custom one is needed).

[ The error looks like (dummy reproducer):

error: unreachable expression
--> rust/kernel/sync.rs:177:5
|
177 | pin_init::stack_pin_init!(let num = 42u32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| unreachable expression
| any code following this expression is unreachable
|
= note: -D unreachable-code implied by -D warnings = help: to override -D warnings add #[allow(unreachable_code)] = note: this error originates in the macro
pin_init::stack_pin_init (in Nightly builds, run with -Z macro-backtrace for more info)

- Miguel ]

[ Reworded for typos. - Miguel ]

Cheers,
Miguel

#4 lore raw
Quoted 2 lines · Gary Guo

We can probably just allow unreachable_code?

Yeah, that works.

Cheers,
Miguel