Closed
Description
Given the following code:
fn foo(x: Option<()>) {
match x {
Some => {},
None => {},
}
}
The current output is:
error[[E0530]](https://doc.rust-lang.org/stable/error-index.html#E0530): match bindings cannot shadow tuple variants
--> src/lib.rs:3:9
|
3 | Some => {},
| ^^^^ cannot be named the same as a tuple variant
For more information about this error, try `rustc --explain E0530`.
error: could not compile `playground` due to previous error
Ideally the output should look like:
error[[E0530]](https://doc.rust-lang.org/stable/error-index.html#E0530): match bindings cannot shadow tuple variants
--> src/lib.rs:3:9
|
3 | Some => {},
| ^^^^ cannot be named the same as a tuple variant
help: try specify the pattern arguments
|
3 | Some(_) => {},
| +++
For more information about this error, try `rustc --explain E0530`.
error: could not compile `playground` due to previous error
One of my colleagues who is new to Rust is familiar with the idea behind pattern matching, but was not aware of all the syntax required to make it work. They made a best guess using the demo above and was puzzled by the error message
In a similar block of code
fn foo(x: Option<()>) {
match x {
Some() => {},
// ^^
None => {},
}
}
the current error looks like this:
error[[E0023]](https://doc.rust-lang.org/stable/error-index.html#E0023): this pattern has 0 fields, but the corresponding tuple variant has 1 field
--> src/lib.rs:3:9
|
3 | Some() => {},
| ^^^^^^ expected 1 field, found 0
|
help: missing parentheses
|
3 | Some(()) => {},
| + +
For more information about this error, try `rustc --explain E0023`.
error: could not compile `playground` due to previous error
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Diagnostics: Confusing error or lint; hard to understand for new users.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Relevant to the compiler team, which will review and decide on the PR/issue.