Description
Code
fn foo() -> Result<(), core::convert::Infallible> {
todo!()
}
fn main() {
match foo() {
Ok(()) => {},
Err(e) => match e {}
}
}
Current output
warning: unreachable pattern
--> src/lib.rs:8:9
|
8 | Err(e) => match e {}
| ^^^^^^
|
= note: this pattern matches no values because `Infallible` is uninhabited
= note: `#[warn(unreachable_patterns)]` on by default
Desired output
Until the 2024 edition, or the code's MSRV is ≥ 1.82, no warning.
Rationale and extra context
Deleting the Err(e) => match e {}
arm will produce code which does not warn on nightly/1.82, but which does not compile on 1.80. This means that users which wish to keep a warning-free-ish nightly (or beta, eventually) build will have to #[allow(unreachable_patterns)]
from now until 1.82 is released, or perhaps even until their next MSRV increase.
Deferring the warning until an edition or explicit MSRV increase seems to me to be a good way to avoid churn in the form of #[allow]
s. Such #[allow]
s are particularly dangerous because unreachable_patterns
is also the lint that detects binding patterns that were intended to be matching against constants instead, so declaring it on a wide scope might hide serious bugs, especially if (as is likely) they're not promptly removed upon the release of 1.82.
Rust Version
1.82.0-nightly (2024-08-11 41dd149fd6a6a06795fc)
Anything else?
I noticed this due to my CI against nightly, but comments on the stabilization PR #122792 (comment) mentioned it first. I'm filing this issue to make sure it is not overlooked by being only visible in that comment thread.
Activity