HELP! Rust analyser highlights entire main function


I have recently updated to Windows 11 and ever since, the Rust-analyser extension of VS Code has become frustrating. In the uploaded SS, I am in the middle of typing a command (line 95) when it TOO promptly highlights the entire main block as erroneous. I wish I could ignore this but this is difficult to work with. You can probably imagine I have to look at this most of the time. Don't know how it happened. Desperately want to fix it.

What's the error message being displayed when you hover over the highlighting?

I general I'm also of the opinion that even when there's a genuine error, hightlighting a whole function line-by-line is super unnecessary, and rust-analyzer should consider some alternative, less distracting form of highlighting large sections of code.

2 Likes

Is the main function annotated with an attribute?
If yes I assume the problem is that the attribute fails to parse the unfinished method-call/field access and as such replaces the function with a compile_error. So you can either turn off attribute expansion(rust-analyzer.experimental.procAttrMacros setting) or you will have to wait for the author of the attribute to fix it so that it doesn't discard the entire function on failure.

1 Like
expected one of: `::`, `<`, `_`, literal, `const`, `ref`, `mut`, `&`, parentheses, square brackets, `..`, `const`\n --- help: attribute can only be applied to functions\u{1b}[1;39mrust-analyzer[macro-error](https://rust-analyzer.github.io/manual.html#macro-error)

let

if let

while let

The error is genuine, a lonesome let is not allowed. BUT I HAVE NOT YET FINISHED TYPING.
Untill I finish a line to the ; I have to bear the christmas light on my whole code segment.

rust-analyser-help-2
I googled function annotations XP
And I think I haven't. Not the main function at least. And importantly it didn't do this, until few days ago.

#[rocket::main] is an annotation in question. This might be considered a bug in rocket, theoretically.

1 Like

Oh. Sorry. Didn't know macros were annotations too. Let me try reporting this to the rocket forums too.

Done! I disabled the rust-analyzer.experimental.procAttrMacros settings and it works fine now!
I have also reported the issue to the Rocket Github forum.
Would love to know where can I know about what the feature is and what do I lose by disabling it.
Thanks a ton!!!

I had a similar issue with normal macros (Over-aggressive span for errors in macro invocation · Issue #10433 · rust-analyzer/rust-analyzer · GitHub ). You might be able to stop the highlighting through:

"rust-analyzer.diagnostics.disabled": [
        "macro-error"
]

In your settings.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.