Rust for Linux List
 help / color / mirror / Atom feed
* [PATCH] rust: pin-init: use irrefutable pattern for `stack_pin_init`
@ 2026-08-28 15:50 Gary Guo
  2026-08-28 15:54 ` Miguel Ojeda
  2026-08-31 23:58 ` Miguel Ojeda
  0 siblings, 2 replies; 5+ messages in thread
From: Gary Guo @ 2026-08-28 15:50 UTC (permalink / raw)
  To: Benno Lossin, Gary Guo, Miguel Ojeda, Boqun Feng,
	Björn Roy Baron, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan
  Cc: Mohamad Alsadhan, rust-for-linux, linux-kernel

From: Gary Guo <gary@garyguo.net>

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.

Reported-by: Mohamad Alsadhan <mo@sdhn.cc>
Closes: https://github.com/Rust-for-Linux/pin-init/pull/171
Signed-off-by: Gary Guo <gary@garyguo.net>
---
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(-)

diff --git a/rust/pin-init/src/lib.rs b/rust/pin-init/src/lib.rs
index 7600cdbbbf98..f1463be9479d 100644
--- a/rust/pin-init/src/lib.rs
+++ b/rust/pin-init/src/lib.rs
@@ -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
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] rust: pin-init: use irrefutable pattern for `stack_pin_init`
  2026-08-28 15:50 [PATCH] rust: pin-init: use irrefutable pattern for `stack_pin_init` Gary Guo
@ 2026-08-28 15:54 ` Miguel Ojeda
  2026-08-31 23:58 ` Miguel Ojeda
  1 sibling, 0 replies; 5+ messages in thread
From: Miguel Ojeda @ 2026-08-28 15:54 UTC (permalink / raw)
  To: Gary Guo
  Cc: Benno Lossin, Miguel Ojeda, Boqun Feng, Björn Roy Baron,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
	Onur Özkan, Mohamad Alsadhan, rust-for-linux, linux-kernel

On Fri, Aug 28, 2026 at 5:50 PM Gary Guo <gary@kernel.org> wrote:
>
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rust: pin-init: use irrefutable pattern for `stack_pin_init`
  2026-08-28 15:50 [PATCH] rust: pin-init: use irrefutable pattern for `stack_pin_init` Gary Guo
  2026-08-28 15:54 ` Miguel Ojeda
@ 2026-08-31 23:58 ` Miguel Ojeda
  2026-09-01  0:22   ` Gary Guo
  1 sibling, 1 reply; 5+ messages in thread
From: Miguel Ojeda @ 2026-08-31 23:58 UTC (permalink / raw)
  To: Gary Guo
  Cc: Benno Lossin, Miguel Ojeda, Boqun Feng, Björn Roy Baron,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
	Onur Özkan, Mohamad Alsadhan, rust-for-linux, linux-kernel

On Fri, Aug 28, 2026 at 5:50 PM Gary Guo <gary@kernel.org> wrote:
>
> From: Gary Guo <gary@garyguo.net>
>
> 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.
>
> Reported-by: Mohamad Alsadhan <mo@sdhn.cc>
> Closes: https://github.com/Rust-for-Linux/pin-init/pull/171
> Signed-off-by: Gary Guo <gary@garyguo.net>

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: stable@vger.kernel.org # 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rust: pin-init: use irrefutable pattern for `stack_pin_init`
  2026-08-31 23:58 ` Miguel Ojeda
@ 2026-09-01  0:22   ` Gary Guo
  2026-09-01  0:27     ` Miguel Ojeda
  0 siblings, 1 reply; 5+ messages in thread
From: Gary Guo @ 2026-09-01  0:22 UTC (permalink / raw)
  To: Miguel Ojeda, Gary Guo
  Cc: Benno Lossin, Miguel Ojeda, Boqun Feng, Björn Roy Baron,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
	Onur Özkan, Mohamad Alsadhan, rust-for-linux, linux-kernel

On Tue Sep 1, 2026 at 12:58 AM BST, Miguel Ojeda wrote:
> On Fri, Aug 28, 2026 at 5:50 PM Gary Guo <gary@kernel.org> wrote:
>>
>> From: Gary Guo <gary@garyguo.net>
>>
>> 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.
>>
>> Reported-by: Mohamad Alsadhan <mo@sdhn.cc>
>> Closes: https://github.com/Rust-for-Linux/pin-init/pull/171
>> Signed-off-by: Gary Guo <gary@garyguo.net>
>
> 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

>
>     Cc: stable@vger.kernel.org # 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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rust: pin-init: use irrefutable pattern for `stack_pin_init`
  2026-09-01  0:22   ` Gary Guo
@ 2026-09-01  0:27     ` Miguel Ojeda
  0 siblings, 0 replies; 5+ messages in thread
From: Miguel Ojeda @ 2026-09-01  0:27 UTC (permalink / raw)
  To: Gary Guo
  Cc: Benno Lossin, Miguel Ojeda, Boqun Feng, Björn Roy Baron,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
	Onur Özkan, Mohamad Alsadhan, rust-for-linux, linux-kernel

On Tue, Sep 1, 2026 at 2:22 AM Gary Guo <gary@garyguo.net> wrote:
>
> We can probably just allow `unreachable_code`?

Yeah, that works.

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-01  0:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-28 15:50 [PATCH] rust: pin-init: use irrefutable pattern for `stack_pin_init` Gary Guo
2026-08-28 15:54 ` Miguel Ojeda
2026-08-31 23:58 ` Miguel Ojeda
2026-09-01  0:22   ` Gary Guo
2026-09-01  0:27     ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox