What it does
Detects let ... else { return; } statements where the remaining function body could be enclosed in a clearer if let block (or if let chain).
Advantage
- Makes the execution scope and intent clearer by explicitly grouping statements that depend on the matched values.
- Reduces boilerplate and vertical space when wrapping short tail logic or function calls.
Drawbacks
- Combining multiple conditions (if let A && let B) relies on the let_chains feature, which may not be stabilized/available on all Rust toolchains.
- Increases rightward drift (indentation) for longer function bodies.
Example
let Some(foo) = foo() else {
return;
};
other(foo);
let Some(foo) = foo() else {
return;
};
let Some(bar) = bar() else {
return;
};
other(foo, bar);
Could be written as:
if let Some(foo) = foo() {
other(foo);
}
if let Some(foo) = foo()
&& let Some(bar) = bar() {
other(foo, bar);
}
Comparison with existing lints
Unlike clippy::manual_let_else (which targets match or if let value assignments), this lint targets let ... else { return; } guard statements and wraps subsequent code in if let scopes.
Additional Context
deally, the restriction lint group could offer two complementary lints so that teams can enforce their preferred coding convention: one favoring if let scoping, and another favoring let ... else guard clauses.
What it does
Detects
let ... else { return; }statements where the remaining function body could be enclosed in a clearerif letblock (orif let chain).Advantage
Drawbacks
Example
Could be written as:
Comparison with existing lints
Unlike
clippy::manual_let_else(which targets match orif letvalue assignments), this lint targetslet ... else { return; }guard statements and wraps subsequent code inif letscopes.Additional Context
deally, the restriction lint group could offer two complementary lints so that teams can enforce their preferred coding convention: one favoring
if letscoping, and another favoringlet ... elseguard clauses.