rust-analyzer: Odd rust-analyzer syntax error

Right now, rust-analyzer is complaining about the syntax in this function that is totally fine for cargo check:

    fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
        if let StatementKind::Assign(box (into, _)) = &statement.kind {
            debug!(
                "visit_statement: statement={:?} local={:?} \
                    never_initialized_mut_locals={:?}",
                statement, into.local, self.never_initialized_mut_locals
            );
            self.remove_never_initialized_mut_locals(*into);
        }

        self.super_statement(statement, location);
    }

In the super_statement line, it says

{
	"resource": "/home/r/src/rust/rustc.3/src/librustc_mir/borrow_check/used_muts.rs",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "Syntax Error: expected field name or number",
	"source": "rust-analyzer",
	"startLineNumber": 92,
	"startColumn": 14,
	"endLineNumber": 92,
	"endColumn": 14
}
{
	"resource": "/home/r/src/rust/rustc.3/src/librustc_mir/borrow_check/used_muts.rs",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "Syntax Error: expected SEMICOLON",
	"source": "rust-analyzer",
	"startLineNumber": 92,
	"startColumn": 14,
	"endLineNumber": 92,
	"endColumn": 14
}

I presume this has something to do with it getting confused while I was typing, and then not properly recovering when I was done typing… the error appeared while I was adding that super_statement line, and it went away after I did “reload window”.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 25 (15 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve been seeing this erroneous “Expected SEMICOLON” multiple times today - first in https://github.com/rust-analyzer/rust-analyzer/issues/4503#issuecomment-776133492 , and then here:

Screen Shot 2021-02-09 at 1 06 42 PM

The red squiggle under ensure in the comment is the same “Expected SEMICOLON” error, and it goes away when I restart Visual Studio.

In my case, I’m transforming Golang code into Rust code, so I’ll copy a chunk of Golang code and slowly transform it. It seems that rust-analyzer gets unrecoverably confused when the Golang code gets pasted in until I restart Visual Studio.

No I have not seen this in a while… but right now, no matter what I do in that file, rust-analyzer doesn’t show any kind of syntax error. So I am not sure how I’d even test this.