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
..
2026-02-22 11:01:08 +00:00
2026-08-23 07:07:46 +05:30
2026-07-18 18:42:03 +02:00
2026-03-10 09:35:03 -04:00
2026-03-10 09:35:03 -04:00
2026-08-13 14:12:34 +02:00
2026-06-08 13:32:41 +03:00
2025-08-05 19:34:46 +05:00
2025-08-05 19:34:46 +05:00
2025-08-05 19:34:46 +05:00
2025-08-05 19:34:46 +05:00
2025-09-03 15:24:49 +02:00
2025-09-03 15:24:49 +02:00
2025-07-04 23:47:31 -07:00
2025-07-04 23:47:31 -07:00
2026-02-25 05:51:37 +00:00
2024-06-13 06:16:12 +00:00
2024-06-13 06:16:12 +00:00
2024-05-20 19:55:59 -07:00
2026-03-10 09:35:03 -04:00
2025-04-30 10:44:24 +03:00
2025-04-30 10:44:24 +03:00
2025-03-14 14:51:58 +08:00
2025-03-14 14:51:58 +08:00
2025-02-17 09:30:40 +11:00
2025-11-06 09:41:16 +08:00
2025-11-06 09:41:16 +08:00
2025-12-13 00:54:20 +09:00
2026-01-31 14:01:54 +01:00
2026-08-13 14:12:34 +02:00
2025-05-03 17:22:52 +02:00
2025-08-09 16:27:20 +05:00
2025-08-09 16:27:20 +05:00
2026-01-18 06:23:47 +01:00
2026-01-18 06:23:47 +01:00
2024-05-20 19:55:59 -07:00
2024-11-23 08:57:25 -07:00
2026-07-22 15:35:11 +02:00
2026-07-22 15:35:11 +02:00
2025-11-27 14:13:58 -05:00
2025-02-10 20:21:39 +00:00
2025-06-03 13:35:31 +02:00
2025-06-03 13:35:31 +02:00
2024-08-19 21:39:57 +02:00
2025-07-10 23:39:54 +08:00
2025-11-09 22:14:48 +00:00
2024-12-04 20:29:36 +00:00
2025-02-10 20:21:39 +00:00
2025-02-10 20:21:39 +00:00
2025-02-10 20:21:39 +00:00
2025-02-10 20:21:39 +00:00
2025-02-10 20:21:39 +00:00
2025-11-24 11:41:52 +09:00
2026-07-21 01:03:16 +03:00
2026-07-21 01:03:16 +03:00
2026-07-21 01:03:16 +03:00
2025-01-29 15:45:13 +00:00
2024-12-04 20:29:36 +00:00
2026-03-17 17:54:01 +00:00
2026-07-22 15:26:51 +02:00
2026-07-22 15:26:51 +02:00
2026-06-18 05:28:05 +02:00
2025-12-16 02:10:08 +09:00
2025-12-16 02:10:08 +09:00
2026-01-18 06:23:47 +01:00
2025-11-27 00:39:52 +09:00
2025-12-09 17:29:23 +00:00
2026-04-12 20:43:28 +05:30
2026-04-12 20:43:28 +05:30
2026-04-12 20:43:28 +05:30
2025-06-03 13:35:31 +02:00
2024-06-13 06:14:32 +00:00
2025-11-13 01:36:35 +09:00
2025-11-13 01:36:35 +09:00
2026-01-31 14:01:54 +01:00
2026-01-31 14:01:54 +01:00
2024-05-15 16:55:54 -04:00
2024-11-22 11:12:15 -08:00
2025-11-09 22:14:48 +00:00
2026-05-08 15:10:37 +08:00
2024-07-04 02:02:21 +00:00
2026-07-21 01:03:16 +03:00
2026-07-21 01:03:16 +03:00
2025-11-27 11:19:00 -05:00
2025-11-27 11:19:00 -05:00
2024-05-20 19:55:59 -07:00
2024-05-20 19:55:59 -07:00
2024-12-04 20:29:36 +00:00
2026-03-17 17:39:59 +08:00
2026-06-04 16:10:12 +00:00
2025-04-08 00:34:40 +02:00
2025-04-08 00:34:40 +02:00
2025-05-08 15:00:17 +00:00
2026-01-31 14:01:54 +01:00
2026-01-31 14:01:54 +01:00
2026-01-31 14:01:54 +01:00
2026-01-31 14:01:54 +01:00
2025-02-05 11:28:24 +00:00
2025-02-05 11:28:24 +00:00
2026-08-13 14:12:34 +02:00
2026-08-13 14:12:34 +02:00
2025-02-10 20:21:39 +00:00
2025-01-08 07:34:59 +00:00
2025-04-08 23:06:31 +03:00
2025-04-08 23:06:31 +03:00
2025-02-14 00:44:10 -08:00
2025-02-14 00:44:10 -08:00
2025-02-10 20:21:39 +00:00
2024-11-23 08:57:25 -07:00
2026-02-17 16:51:44 +00:00
2026-08-13 14:12:34 +02:00
2025-06-03 07:38:06 +05:00
2025-06-03 07:38:06 +05:00
2026-03-28 16:18:11 +09:00
2025-10-18 01:20:25 +00:00
2024-08-26 18:30:15 -04:00
2025-07-25 20:38:54 +05:00
2025-12-17 14:53:14 +00:00
2025-08-09 16:27:20 +05:00
2025-08-09 16:27:20 +05:00
2025-04-03 21:41:58 +00:00
2026-04-09 01:08:52 +02:00
2024-11-21 18:40:36 +08:00
2026-04-23 22:28:00 +02:00
2024-11-22 11:12:15 -08:00
2025-08-19 21:27:10 +02:00
2025-06-11 15:30:15 +01:00
2025-08-09 16:27:20 +05:00
2025-02-10 20:21:39 +00:00
2025-02-10 20:21:39 +00:00
2026-04-20 22:21:51 +08:00
2025-08-09 16:27:20 +05:00
2025-08-09 16:27:20 +05:00
2026-05-26 02:01:52 +08:00
2026-05-26 02:01:52 +08:00
2026-05-26 02:01:52 +08:00
2026-01-16 20:55:37 +01:00
2026-01-16 20:55:37 +01: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
2025-08-05 19:34:46 +05:00
2024-07-11 00:18:47 +08:00
2024-07-11 00:18:47 +08:00
2026-07-17 23:47:37 +02:00
2026-07-20 20:27:27 +02:00
2026-07-20 20:27:27 +02:00
2025-01-08 00:13:43 +00:00
2025-01-08 00:13:43 +00:00
2026-08-13 14:12:34 +02:00
2026-08-13 14:12:34 +02:00
2026-07-21 01:03:16 +03:00
2026-07-21 01:03:16 +03:00
2025-08-05 19:34:46 +05:00
2025-08-09 16:27:20 +05:00
2026-02-25 05:51:37 +00:00
2026-01-14 20:54:27 +01:00
2026-01-14 20:54:27 +01:00
2026-07-23 19:57:43 +02:00
2026-07-23 19:57:43 +02:00
2025-04-08 21:05:20 +00:00
2025-04-08 21:05:20 +00:00
2025-08-02 15:29:16 -04:00
2025-08-09 16:27:20 +05:00
2025-08-09 16:27:20 +05:00
2025-08-10 11:54:15 -04:00
2025-08-10 11:54:15 -04:00
2025-05-22 12:52:46 +01:00