From 0cae953c75d14c5fe766b3e413da2989f25fd11e Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Fri, 28 Aug 2026 16:35:20 +0100 Subject: [PATCH] use irrefutable pattern for `stack_pin_init` 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 Closes: https://github.com/Rust-for-Linux/pin-init/pull/171 Signed-off-by: Gary Guo --- src/lib.rs | 8 +------- tests/ui/compile-fail/init/no_error_coercion.stderr | 4 ++-- tests/ui/compile-fail/pin_data/missing_pin.stderr | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7600cdbb..f1463be9 100644 --- a/src/lib.rs +++ b/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); }; } diff --git a/tests/ui/compile-fail/init/no_error_coercion.stderr b/tests/ui/compile-fail/init/no_error_coercion.stderr index 974c3c15..ddc13df7 100644 --- a/tests/ui/compile-fail/init/no_error_coercion.stderr +++ b/tests/ui/compile-fail/init/no_error_coercion.stderr @@ -7,8 +7,8 @@ error[E0277]: `?` couldn't convert the error to `std::alloc::AllocError` 19 | | }? AllocError) | | ^ | | | - | |______________________the trait `From` is not implemented for `std::alloc::AllocError` - | this can't be annotated with `?` because it has type `Result<_, Infallible>` + | |______________________the trait `From` is not implemented for `std::alloc::AllocError` + | this can't be annotated with `?` because it has type `Result<_, !>` | = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait = note: this error originates in the macro `init` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/compile-fail/pin_data/missing_pin.stderr b/tests/ui/compile-fail/pin_data/missing_pin.stderr index f480b637..fa39129f 100644 --- a/tests/ui/compile-fail/pin_data/missing_pin.stderr +++ b/tests/ui/compile-fail/pin_data/missing_pin.stderr @@ -8,7 +8,7 @@ error[E0277]: the trait bound `impl PinInit: Init` is not satis | |__________- required by a bound introduced by this call | help: the trait `Init` is not implemented for `impl PinInit` - but trait `Init, Infallible>` is implemented for it + but trait `Init, !>` is implemented for it --> src/lib.rs | | unsafe impl Init for T {}