Notice the capitalization (playground):
fn f() {
While let Some(x) = vec![].next() {
//
}
}
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found keyword `let`
--> src/lib.rs:2:11
|
2 | While let Some(x) = vec![].next() {
| ^^^ expected one of 8 possible tokens
Instead it would be nice to say
error: `While` is not a keyword
--> src/lib.rs:2:11
|
2 | While let Some(x) = vec![].next() {
| ^^^^^ help: try `while` instead
This is not just for while (playground):
fn main() {
Let x = "hello";
}
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `x`
--> src/main.rs:2:9
|
2 | Let x = "hello";
| ^ expected one of 8 possible tokens
Perhaps in general it might be nice to do some kind of Levenshtein distance for identifiers that might be intended to be keywords? Might be tricky to implement though, and probably not necessary.
@jyn514 Do you want to update the title since this would be nice to have for other keywords as well?
I think there is a lot for this, like Fn main. But I don't know if this is worth it.
If I didn't think it was worth it, I wouldn't have opened the issue.
@camelid FYI I don't think newcomer-roadblock is _wrong_ per-se, but I opened this because I made the typo myself and was very confused for a second 馃槅
I don't know; I would consider it newcomer-roadblock. This is a pretty confusing error:
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `x`
--> src/main.rs:2:9
|
2 | Let x = "hello";
| ^ expected one of 8 possible tokens
In general, Rust's parse errors can sometimes be a bit confusing (for me at least). It would just be nice if they were more semantic errors, rather than what token the parser expected and what it got. I think that format is more understandable to compiler developers than to regular programmers ;)
guys, I really wanna do a related task to the parser, if you give me a little information that which part of the parser I should work on, I can start working on it
@hosseind75 I am also a bit now on this but my guess is that this is probably not a very easy task to begin with.
Or maybe check in compiler/rustc_parse/src/parser/expr.rs or somewhere around there? My guess is somewhere around parse_lit but maybe @estebank can give you a more detailed mentor instructions.
sure I will check, thanks
@estebank sorry can you give me a little instructions about how to fix this issue馃槄?
I want to start it but I need some details