# "Irrefutable Pattern" Warnings in Let Chains

**URL:** <https://internals.rust-lang.org/t/irrefutable-pattern-warnings-in-let-chains/17238>\
**Category:** language design\
**Created:** [August 22, 2022, 1:39pm UTC](https://internals.rust-lang.org/t/irrefutable-pattern-warnings-in-let-chains/17238 "2022-08-22T13:39:48Z")\
**Posts on this page:** 1\
**Showing post:** 40

<div class="post-metadata">

**Author:** ![tczajka](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tczajka/32/8923_2.png) [@tczajka](https://internals.rust-lang.org/u/tczajka)\
**Post date:** [August 26, 2022, 7:33am UTC](https://internals.rust-lang.org/t/irrefutable-pattern-warnings-in-let-chains/17238/40 "2022-08-26T07:33:50Z")

</div>

> [@CAD97](#):
>
> So considering this example, I do think it might be reasonable to relax the irrefutable binding lint for the case where
> 
> - the value is bound; and
> - the value's type has a semantic drop.

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:

```rust
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:

```rust
{
    let potential_answer = calculate();
    if valid_answer(&potential_answer) {
        return potential_answer;
    }
}

```

> [@CAD97](#):
>
> If all patterns in an `if let` chain are irrefutable and no boolean tests exist, lint; it is better to just use a normal block and `let`s inside the block.

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.

---

_[View the full topic](https://internals.rust-lang.org/t/irrefutable-pattern-warnings-in-let-chains/17238)._
