rust-lang / rust-analyzer

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

Reserved keywords in macros are highlighted as keywords #18039

Closed allan2 closed 6 days ago

allan2 commented 1 week ago

RA 0.4.2095-standalone rustc 1.82 nightly VS Code 1.92.2

Reserved keywords in macros are highlighted as keywords rather than regular tokens when used in macros.

// working code
#[my_attr_macro(mut = true, override = true, foo = true)]
fn main() {
    my_macro!(
        mut = true,
        override = false,
        foo = true,
    );
}

vs-code-screenshot.png

### Tasks
Veykril commented 1 week ago

That sounds correct to me. These tokens are considered keywords in the language so they should be highlighted as such (unless their span is re-used for something else in the expansion)

allan2 commented 6 days ago

That makes sense.

I switched to a different implementation of attribute parsing (syn 1 AttributeArgs to syn 2 impl Parse), which errors with error: expected identifier, found keyword `override`.

Even though a keyword could used as an identifier, I don't think RA can tell. And it was useful to have it highlighted for me.