Closed
Description
match S::get(1) {
Some(Val::Foo) => ();
_ => (),
}
The current output is:
error: expected one of `,`, `.`, `?`, `}`, or an operator, found `;`
--> src/main.rs:26:29
|
26 | Some(Val::Foo) => ();
| -- ^ expected one of `,`, `.`, `?`, `}`, or an operator
| |
| while parsing the `match` arm starting here
error[E0283]: type annotations needed
--> src/main.rs:25:11
|
4 | fn get<K, V: Default>(_: K) -> Option<V> {
| ------- required by this bound in `S::get`
...
25 | match S::get(1) {
| ^^^^^^ cannot infer type for type parameter `V` declared on the associated function `get`
|
= note: cannot satisfy `_: Default`
help: consider specifying the type arguments in the function call
|
25 | match S::get::<K, V>(1) {
| ^^^^^^^^
The first error is a generic parse error that we could account for. The second is an inference error that would be completely solved if the parse error was recovered more gracefully.
Ideally, for a generic case the output should look like:
error: expected one of `,`, `.`, `?`, `}`, or an operator, found `;`
--> src/main.rs:26:29
|
26 | Some(Val::Foo) => ();
| -- ^ expected one of `,`, `.`, `?`, `}`, or an operator
| |
| while parsing the `match` arm starting here
help: you likely meant to write a match arm block
|
26 | Some(Val::Foo) => { (); }
| ^ ^
while for a case where a single statement is found we could also suggest:
error: expected one of `,`, `.`, `?`, `}`, or an operator, found `;`
--> src/main.rs:26:29
|
26 | Some(Val::Foo) => ();
| -- ^ expected one of `,`, `.`, `?`, `}`, or an operator
| |
| while parsing the `match` arm starting here
help: you might have meant to write a match arm expression separator
|
26 | Some(Val::Foo) => (),
| ^
Taken from https://twitter.com/mcclure111/status/1364998004852236289
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: The lexing & parsing of Rust source code to an ASTDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: An error or lint that needs small tweaks.Relevant to the compiler team, which will review and decide on the PR/issue.