Repository: rust
Issue: Nested match not being treated as an expression
Labels: A-diagnostics,A-parser,T-compiler,C-bug,D-papercut

Apologies if this has been reported before. I'm not sure what keywords I could use to find a similar issue. I tried this code:

```rust
fn main() {
    let a = match 1 {
        1 => match 2 {
            2 => true,
            _ => false
        } && true,
        _ => false
    };
}
```

I expected to see this happen: the code compiles, and `a` ends up being `true`.

Instead, this happened: the inner `match` does not seem to be treated as an expression and fails as follows:

```
   Compiling playground v0.0.1 (/playground)
error: unexpected `,` in pattern
 --> src/main.rs:6:18
  |
6 |         } && true,
  |                  ^
  |
help: try adding parentheses to match on a tuple...
  |
6 ~         } (&& true,
7 ~         _) => false
  |
help: ...or a vertical bar to match on multiple alternatives
  |
6 ~         } && true |
7 ~         _ => false
  |

error: could not compile `playground` due to previous error
```

Neither of the suggestions fix the problem. However, writing `true && match 2` instead, or adding parenthesis around the entire inner `match` expression does solve the problem:

```rust
fn main() {
    let a = match 1 {
        1 => (match 2 {
            2 => true,
            _ => false
        }) && true,
        _ => false
    };
}
```

---

The following code also fails:

```rust
fn main() {
    let a = match 1 {
        1 => {
            match 2 {
                2 => true,
                _ => false
            } && true
        },
        _ => false
    };
}
```

But this time with another error (it thinks I meant `&&true` as in `&&bool`):

```
Compiling playground v0.0.1 (/playground)
error[[E0308]](https://doc.rust-lang.org/nightly/error-index.html#E0308): mismatched types
 --> src/main.rs:4:13
  |
4 | /             match 2 {
5 | |                 2 => true,
6 | |                 _ => false
7 | |             } && true
  | |             ^- help: consider using a semicolon here
  | |_____________|
  |               expected `()`, found `bool`

error[[E0308]](https://doc.rust-lang.org/nightly/error-index.html#E0308): `match` arms have incompatible types
  --> src/main.rs:9:14
   |
2  |       let a = match 1 {
   |  _____________-
3  | |         1 => {
4  | |             match 2 {
5  | |                 2 => true,
6  | |                 _ => false
7  | |             } && true
   | |               ------- this is found to be of type `&&bool`
8  | |         },
9  | |         _ => false
   | |              ^^^^^ expected `&&bool`, found `bool`
10 | |     };
   | |_____- `match` arms have incompatible types

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to 2 previous errors
```

Wrapping the inner `match` in `()` fixes it. Writing `true && match 2` instead also fixes it.

Both of the failing examples also seem to work if the inner `match` is not nested and it's the only `match` in the code.

### Meta

`rustc --version --verbose`:
```
Nightly channel

Build using the Nightly version: 1.65.0-nightly

(2022-08-30 02654a0844f5c8d29bac)
```