diff options
author | bors <bors@rust-lang.org> | 2023-04-09 20:57:06 +0000 |
---|---|---|
committer | bors <bors@rust-lang.org> | 2023-04-09 20:57:06 +0000 |
commit | 696aaad58c57a589f6fb2ecff5bae2eec581cb71 (patch) | |
tree | e7e3dba6b267106715eac55d28834b6dec753cc8 /tests/rustdoc-js-std/parser-errors.js | |
parent | 39bf7777aab9ac1f6b0802cd52cd91d6e021aa91 (diff) | |
parent | 3b38dd91126a647334af07d772ad809422918e5a (diff) | |
download | rust-696aaad58c57a589f6fb2ecff5bae2eec581cb71.tar.gz |
Auto merge of #109760 - MaciejWas:struct-tuple-field-names-suggestion, r=jackh726
Better diagnostic when pattern matching tuple structs
Fixes #108284
When trying to pattern match a tuple struct we might get a flawed error message if there are missing fields. E.g.
```
let x = Foo(100, 200);
if let Foo { 0: bar } = x { ... }
```
Produces this error:
```
error[E0769]: tuple variant `Foo` written as struct variant
--> hello.rs:5:12
|
5 | if let Foo { 0: foo } = x {
| ^^^^^^^^^^^^^^
|
help: use the tuple variant pattern syntax instead
|
5 | if let Foo(_, _) = x {
| ~~~~~~
```
Which doesn't highlight that we can still use the struct syntax but we need to fill missing fields. This pr changes this error to:
```
error[E0027]: pattern does not mention field `1`
--> hello.rs:5:12
|
5 | if let Foo { 0: foo } = x {
| ^^^^^^^^^^^^^^ missing field `1`
|
help: include the missing field in the pattern
|
5 | if let Foo { 0: foo, 1: _ } = x {
| ~~~~~~~~
help: if you don't care about this missing field, you can explicitly ignore it
|
5 | if let Foo { 0: foo, .. } = x {
| ~~~~~~
```
Diffstat (limited to 'tests/rustdoc-js-std/parser-errors.js')
0 files changed, 0 insertions, 0 deletions