]> git.lizzy.rs Git - rust.git/commit - src/tools/rust-analyzer
Rollup merge of #95008 - c410-f3r:let-chains-paren, r=wesleywiser
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>
Mon, 11 Apr 2022 18:00:40 +0000 (20:00 +0200)
committerGitHub <noreply@github.com>
Mon, 11 Apr 2022 18:00:40 +0000 (20:00 +0200)
commit2ad701e45036fb2ccab8d4b4e23f9a3325e12817
treee3d2525106965b176aaecf20ca9fde36e80cc198
parent625e4dd13a3abd0cc59807af66c3c4cd63440852
parent6ee3c47a3a41c495fcf52f342fe4253231a257c8
Rollup merge of #95008 - c410-f3r:let-chains-paren, r=wesleywiser

[`let_chains`] Forbid `let` inside parentheses

Parenthesizes are mostly a no-op in let chains, in other words, they are mostly ignored.

```rust
let opt = Some(Some(1i32));

if (let Some(a) = opt && (let Some(b) = a)) && b == 1 {
    println!("`b` is declared inside but used outside");
}
```

As seen above, such behavior can lead to confusion.

A proper fix or nested encapsulation would probably require research, time and a modified MIR graph so in this PR I simply denied any `let` inside parentheses. Non-let stuff are still allowed.

```rust
fn main() {
    let fun = || true;

    if let true = (true && fun()) && (true) {
        println!("Allowed");
    }
}
```

It is worth noting that `let ...`  is not an expression and the RFC did not mention this specific situation.

cc `@matthewjasper`