rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.35k stars 1.62k forks source link

Incorrect brace highlighting when using character constants in generic const variables #17669

Closed Qix- closed 4 months ago

Qix- commented 4 months ago

Prefacing this by saying I'm not entirely sure r-a is to blame here. I couldn't find where the syntax highlighting was coming from, so this might be a VSCode issue. Just let me know and I can move the issue over there if need be.

rust-analyzer version: rust-analyzer version: 0.3.2037-standalone

rustc version: rustc 1.80.0-nightly (804421dff 2024-06-07)

editor or extension: VSCode 1.91.1

relevant settings: Nothing unusual.

repository link (if public, optional): N/A

code snippet to reproduce:

#[derive(Default)]
struct Foo<const C: u8>;

fn foobar() {
    let c: Foo<b'}'> = Default::default();
}

This is valid rust that breaks syntax highlighting.

The constant can either be b'}', which results in this incorrect highlighting (final } is red, indicating error):

image

or b'{' (initial { is red):

image

Further, the constant itself is highlighted as though it is part of the syntax and not part of a character constant.

In the simple example it's a bit innocuous but in the larger codebase I initially found this in it started to really get confusing as small, subtle highlighting issues started to cascade through the bits under the constant.

Veykril commented 4 months ago

rust-analyzer does set the colorizedBracketPairs language configuration but I am not aware of any way to tell VSCode in what contexts not to consider these unfortunately

Qix- commented 4 months ago

FWIW it appears all character constants are being parsed incorrectly here, regardless of them being { or }.

image

Veykril commented 4 months ago

As in their color is incorrect? Can you put the cursor on one of those incorrect lit characters, run the Inspect Editor Tokens and Scopes command and paste the output?

Qix- commented 4 months ago

All taken from https://github.com/oro-os/qdb/blob/9496bd17903f23a64ef077e07124a72eff6bcdae/src/gdb.rs:

Incorrect: image

Correct: image

Incorrect: image

Incorrect: image

Incorrect: image

Veykril commented 4 months ago

Ah, do you have semantic highlighting disabled? Then this is a VSCode issue, rust-analyzer does not ship with a textmate grammar so this is likely a bug with vscode's textmate grammar

Qix- commented 4 months ago

I don't think I've explicitly disabled it but yeah it appears to be an issue with the textmate grammar. I'll open an issue over there, then :)

Thanks for investigating either way!