-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
misleading "try adding parentheses" in match with comma #54807
Comments
I disagree. It could be either of these. At the point where we're suggesting this we don't know the type of the match or any other details. We could suggest both |
This seems like a nice first issue for a beginner like me to contribute to, so I'd be happy to tackle this one. |
I don't know where the suggestions are mades but in this case (A,B) is obviously wrong, as it doesn't type check, while A|B does :) |
We have no way to distinguish between your code sample and the following code sample. fn x(e: (u8, u8)) -> i32 {
match e {
A,B => 1,
C => 2
}
} The error is happening during parsing. This means we have no type information available. All we know is that we're parsing a pattern. Think about it this way, what can you tell about the following code snippet: match e {
A,B => 1,
C => 2
} Just looking at that without looking at the surroundings tells you nothing, except that |
@11Takanori Just checking in - have you made progress on this issue? Willing to pitch in on it. I'd like to slightly modified the initial code with: enum E {A, B, C}
fn foo(e: E) -> u32 {
match e {
E::A,E::B => 0,
E::C => 1
}
} Error message is the same, but you can see that the compiler has more information, and still giving the wrong message. |
Is anyone working on this issue? I'm a first-timer but want to try. |
…eses-in-match-with-comma, r=oli-obk suggest `|` when `,` founds in invalid match value Issue rust-lang#54807 I get stuck on (what | how) I should implement...
…eses-in-match-with-comma, r=oli-obk suggest `|` when `,` founds in invalid match value Issue rust-lang#54807 I get stuck on (what | how) I should implement...
…eses-in-match-with-comma, r=oli-obk suggest `|` when `,` founds in invalid match value Issue rust-lang#54807 I get stuck on (what | how) I should implement...
…eses-in-match-with-comma, r=oli-obk suggest `|` when `,` founds in invalid match value Issue rust-lang#54807 I get stuck on (what | how) I should implement...
Consider the following (incorrect) code.
The comma in the match is obviously supposed to be a
|
. However, rustc recommends I rewrite to(A,B)
, which makes the situation worse, as the compile error becomesexpected enum E, found tuple
.The text was updated successfully, but these errors were encountered: