I agree that the warning should be relaxed in some cases, especially since irrefutable patterns already are an accepted style in the middle of a let chain.
I think it should be relaxed for all cases when the first let
in the chain (but not the last let
in the chain) binds a variable, regardless of whether there is drop glue on its type.
Scoping a variable locally is convenient regardless of whether or not there is drop glue. It would be confusing if the warning allowed it for some types and not for others.
Example:
if let potential_answer = calculate() &&
valid_answer(&potential_answer) {
return potential_answer;
}
With your proposal, this would be a lint for i32
but not for Vec<i32>
. I think if the lint is relaxed, it should be relaxed in this case for all types.
The alternative is to either keep potential_answer
in scope longer than necessary, or use extra braces, similarly to your handle
example:
{
let potential_answer = calculate();
if valid_answer(&potential_answer) {
return potential_answer;
}
}
This is already covered by the warning on the last let
in the chain being irrefutable. That never makes sense, and shouldn't be relaxed.