-
Notifications
You must be signed in to change notification settings - Fork 14k
Improve suggestion for tuple struct pattern matching errors. #81235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,9 @@ error[E0769]: tuple variant `S` written as struct variant | |
| --> $DIR/missing-fields-in-struct-pattern.rs:4:12 | ||
| | | ||
| LL | if let S { a, b, c, d } = S(1, 2, 3, 4) { | ||
| | ^^^^^^^^^^^^^^^^ help: use the tuple variant pattern syntax instead: `S(a, b, c, d)` | ||
| | -^^^^^^^^^^^^^^^ | ||
| | | | ||
| | help: use the tuple variant pattern syntax instead: `(a, b, c, d)` | ||
|
||
|
|
||
| error: aborting due to previous error | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| struct S(i32, f32); | ||
| enum E { | ||
| S(i32, f32), | ||
| } | ||
| fn main() { | ||
| let x = E::S(1, 2.2); | ||
| match x { | ||
| E::S { 0, 1 } => {} | ||
| //~^ ERROR tuple variant `E::S` written as struct variant [E0769] | ||
| } | ||
| let y = S(1, 2.2); | ||
| match y { | ||
| S { } => {} //~ ERROR: tuple variant `S` written as struct variant [E0769] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| error[E0769]: tuple variant `E::S` written as struct variant | ||
| --> $DIR/struct-tuple-field-names.rs:8:9 | ||
| | | ||
| LL | E::S { 0, 1 } => {} | ||
| | ----^^^^^^^^^ | ||
| | | | ||
| | help: use the tuple variant pattern syntax instead: `(_, _)` | ||
|
|
||
| error[E0769]: tuple variant `S` written as struct variant | ||
| --> $DIR/struct-tuple-field-names.rs:13:9 | ||
| | | ||
| LL | S { } => {} | ||
| | -^^^^ | ||
| | | | ||
| | help: use the tuple variant pattern syntax instead: `(_, _)` | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0769`. |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is fair (as you're just copying from existing logic), but ideally we would not be using
span_to_snippethere. (No need to change this now.)