-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
pub fn say_hello(name: Option<String>) {
let name_str = Some(name) else {
println!("Hello person!");
return;
};
// TODO: greet the user by name.
}Current output
warning: irrefutable `let...else` pattern
--> src/lib.rs:2:5
|
2 | let name_str = Some(name) else {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this pattern will always match, so the `else` clause is useless
= help: consider removing the `else` clause
= note: `#[warn(irrefutable_let_patterns)]` on by defaultDesired output
warning: unreachable `else` clause
--> src/lib.rs:2:5
|
2 | let name_str = Some(name) else {
| ^^^^
|
= note: this pattern will match anything
= help: consider using `let Some(name_str)` to match on a specific variant
= note: `#[warn(irrefutable_let_patterns)]` on by defaultRationale and extra context
This took me a minute to realise what I was doing wrong: the code doesn't look obviously wrong at first glance.
The irrefutable message is also a little opaque to me. I know 'irrefutable' is in the warning name irrefutable_let_patterns, but does it need to be in the prose? E.g. would something like this better (inspired by unreachable_code)?
warning: `let...else` has unreachable `else` block
Other cases
Rust Version
rustc 1.95.0-nightly (7f99507f5 2026-02-19)
binary: rustc
commit-hash: 7f99507f57e6c4aa0dce3daf6a13cca8cd4dd312
commit-date: 2026-02-19
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 22.1.0Anything else?
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.