Files
rust/tests/ui/pattern
Jacob Pratt 4e637b3c68 Rollup merge of #160279 - ArneshBanerjee:recover-tuple-type-ascription, r=fmease
Recover from tuple patterns with inline element types

If you write the element types inside a tuple pattern:

```rust
let (a: bool, b: u8) = (true, 1);
```

the error you get doesn't really explain the problem:

```
error: expected one of `)`, `,`, `@`, `if`, or `|`, found `:`
 --> src/main.rs:2:11
  |
2 |     let (a: bool, b: u8) = (true, 1);
  |           ^ expected one of `)`, `,`, `@`, `if`, or `|`
```

A let pattern can have a type after it, so now we point out what to do instead:

```
help: to annotate the types of a tuple's elements, write them as a tuple type after the pattern
  |
2 -     let (a: bool, b: u8) = (true, 1);
2 +     let (a, b): (bool, u8) = (true, 1);
  |
```

If an element doesn't have a type written, it just gets `_`, so `(a: bool, b)`
turns into `(a, b): (bool, _)`.

I kept this to let bindings only. That's the case where the pattern doesn't need
a type of its own, so once the types move into the suggestion the rest of the
statement parses fine and you get a single error instead of a pile of follow-up
ones. Match arms, nested patterns and function parameters are left alone.

Closes rust-lang/rust#149246
2026-08-23 05:59:33 -04:00
..
2025-08-05 19:34:46 +05:00
2025-08-05 19:34:46 +05:00
2025-08-09 16:27:20 +05:00
2025-11-27 14:13:58 -05:00
2026-06-18 05:28:05 +02:00
2025-11-27 11:19:00 -05:00
2025-08-09 16:27:20 +05:00
2024-11-21 18:40:36 +08:00
2025-06-11 15:30:15 +01:00
2025-08-09 16:27:20 +05:00
2025-08-09 16:27:20 +05:00
2025-08-09 16:27:20 +05:00
2025-08-05 19:34:46 +05:00
2026-07-17 23:47:37 +02:00
2025-08-05 19:34:46 +05:00
2025-08-09 16:27:20 +05:00
2026-07-23 19:57:43 +02:00