Given the following code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4afb15166fa46eb6f2eaf2ba053d9501
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
Given the following code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4afb15166fa46eb6f2eaf2ba053d9501
The current output is:
Ideally the output should look like:
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
the current error looks like this: