-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Improve suggestion for tuple struct pattern matching errors. #81235
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)` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The span in all of the tests' suggestions seems to now be wrong. The resulting code would be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The suggestion here seemed like you were suggesting to remove the path from the help text. It seems like I misunderstood the intent there, what were you suggesting to use instead of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My proposal is to use In the case highlighted above, you had a span pointing at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha, having that suggestion with |
||
|
||
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`. |
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_snippet
here. (No need to change this now.)