-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Using a tuple-like data type with a record-like pattern (or vice versa) produces an opaque diagnostic #41314
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
Comments
Here's a much better error message, from a similar case:
|
The problem is that match X::Y(0) {
X::Y { 0: data } => ()
} is legal, as well as match X::Y(0) {
X::Y { .. } => ()
} |
Then a note could be added. |
Could you give a concrete example? (How the note looks and when it is triggered.) |
Something like this...
triggered when the syntactic form of the variant does not match the syntactic form of the pattern |
|
Hi, I'm going to try to fix this now. First time working on the rust code but it makes sense so far! |
@thombles, feel free to reach out with any questions you might have! |
I've made the change and it looks like this. thombles@8a66362
I just have a couple of questions before I put up a PR...
I see that we already have E0532 for the opposite direction:
Thanks! |
It should cover this issue.
Correct.
Yes :(
I recommend to find a test reporting this error in
|
Thanks @petrochenkov! The existing compile-fail test covered matching a struct so I made a new UI test to exercise this scenario. I've made a PR now. |
Improve diagnostics when attempting to match tuple enum variant with struct pattern Adds an extra note as below to explain that a tuple pattern was probably intended. ``` error[E0026]: variant `X::Y` does not have a field named `data` --> src/main.rs:18:16 | 18 | X::Y { data } => println!("The data is {}", data) | ^^^^ variant `X::Y` does not have field `data` error[E0027]: pattern does not mention field `0` --> src/main.rs:18:9 | 18 | X::Y { data } => println!("The data is {}", data) | ^^^^^^^^^^^^^ missing field `0` | = note: trying to match a tuple variant with a struct variant pattern ``` Solution for rust-lang#41314.
Improve diagnostics when attempting to match tuple enum variant with struct pattern Adds an extra note as below to explain that a tuple pattern was probably intended. ``` error[E0026]: variant `X::Y` does not have a field named `data` --> src/main.rs:18:16 | 18 | X::Y { data } => println!("The data is {}", data) | ^^^^ variant `X::Y` does not have field `data` error[E0027]: pattern does not mention field `0` --> src/main.rs:18:9 | 18 | X::Y { data } => println!("The data is {}", data) | ^^^^^^^^^^^^^ missing field `0` | = note: trying to match a tuple variant with a struct variant pattern ``` Fixes #41314.
Uh oh!
There was an error while loading. Please reload this page.
One of the ways to reproduce:
This results in:
I think the error message would have been much better if it just said outright that
variant X::Y requires a tuple pattern
or something like that (I'm not sure what the proper terminology is...)This happens fairly often during refactoring.
The text was updated successfully, but these errors were encountered: