Skip to content
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

Cryptic errors for top-level let statements. #14963

Closed
LouisGariepy opened this issue Jun 4, 2023 · 0 comments · Fixed by #15961
Closed

Cryptic errors for top-level let statements. #14963

LouisGariepy opened this issue Jun 4, 2023 · 0 comments · Fixed by #15961
Labels
A-parser parser issues C-enhancement Category: enhancement

Comments

@LouisGariepy
Copy link

Versions

rust-analyzer: v0.4.1539
rustc: 1.70.0

Reproducer

Simply write a top-level let statement.

let x = 1;

Explanation

Hovering the let keyword gives

Syntax Error: expected an itemrust-analyzer syntax-error
expected item, found keyword let
consider using const or static instead of let for global variables

Hovering the whitespace between let and x

Syntax Error: expected an item rust-analyzer syntax-error
expected item, found keyword let
consider using const or static instead of let for global variables
Syntax Error: expected BANG rust-analyzer syntax-error
Syntax Error: expected {, [, ( rust-analyzer syntax-error
Syntax Error: expected SEMICOLON rust-analyzer syntax-error

Hovering x gives

Syntax Error: expected BANG rust-analyzer syntax-error
Syntax Error: expected {, [, ( rust-analyzer syntax-error
Syntax Error: expected SEMICOLON rust-analyzer syntax-error

Likewise, hovering the rest of parts of the statement gives similar yet slightly different messages.

As you can see, some of those messages are surprising.

The red underline squiggles are also a bit surprising:

Screenshot from 2023-06-04 00-12-50

What I expected

I expected the whole statement to be underlined consistently, and the hover message to only contain the relevant error message (i.e. the one that you get when hovering the let keyword, see section above).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser parser issues C-enhancement Category: enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants