Skip to content

Conversation

kevinmehall
Copy link
Contributor

In rustc and proc-macro2, a bare _ token is parsed for procedural macro purposes as Ident rather than Punct (see rust-lang/rust#48842). This changes rust-analyzer to match rustc's behavior and implementation by handling _ as an Ident in token trees, but explicitly preventing $x:ident from matching it in MBE.

proc macro crate:

#[proc_macro]
pub fn input(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    dbg!(input)
}

test crate:

test_proc_macro::input!(_);

output (rustc):

[test-proc-macro/src/lib.rs:10] input = TokenStream [
    Ident {
        ident: "_",
        span: #0 bytes(173..174),
    },
]

output (rust-analyzer before this change):

[test-proc-macro/src/lib.rs:10] input = TokenStream [
    Punct {
        ch: '_',
        spacing: Joint,
        span: 4294967295,
    },
]

output (rust-analyzer after this change):

[test-proc-macro/src/lib.rs:10] input = TokenStream [
    Ident {
        ident: "_",
        span: 4294967295,
    },
]

Copy link
Contributor

@edwin0cheng edwin0cheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM , just a little nit

@edwin0cheng
Copy link
Contributor

Thanks !

bors r+

@bors
Copy link
Contributor

bors bot commented Mar 21, 2021

@bors bors bot merged commit 787bd3c into rust-lang:master Mar 21, 2021
@lnicola
Copy link
Member

lnicola commented Mar 21, 2021

changelog fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants