forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#109760 - MaciejWas:struct-tuple-field-names-s…
…uggestion, r=jackh726 Better diagnostic when pattern matching tuple structs Fixes rust-lang#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 { | ~~~~~~ ```
- Loading branch information
Showing
3 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters