Skip to content

Cryptic errors for top-level let statements. #14963

Closed
@LouisGariepy

Description

@LouisGariepy

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions