-
Notifications
You must be signed in to change notification settings - Fork 2k
False positive for let_and_return #16820
Copy link
Copy link
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-bugIssue: The suggestion compiles but changes the code to behave in an unintended wayIssue: The suggestion compiles but changes the code to behave in an unintended way
Description
Summary
Seems like it doesn't account for let-else statements which meaningfully change program logic
Lint Name
let_and_return
Reproducer
I tried this code:
fn minimal() -> Option<i32> {
let value = Some(42);
let v @ None = value else {
panic!("uh oh!");
};
v
}I saw this happen:
warning: returning the result of a `let` binding from a block
--> src/lib.rs:8:5
|
4 | / let v @ None = value else {
5 | | panic!("uh oh!");
6 | | };
| |______- unnecessary `let` binding
7 |
8 | v
| ^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.94.0/index.html#let_and_return
= note: `#[warn(clippy::let_and_return)]` on by default
help: return the expression directly
|
4 ~
5 |
6 ~ value
|
I expected to see this happen:
No warning, the let binding is necessary
Version
rustc 1.94.1 (e408947bf 2026-03-25)
binary: rustc
commit-hash: e408947bfd200af42db322daf0fadfe7e26d3bd1
commit-date: 2026-03-25
host: x86_64-unknown-linux-gnu
release: 1.94.1
LLVM version: 21.1.8
Additional Labels
@rustbot label +I-suggestion-causes-bug
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-bugIssue: The suggestion compiles but changes the code to behave in an unintended wayIssue: The suggestion compiles but changes the code to behave in an unintended way
Type
Fields
Give feedbackNo fields configured for issues without a type.