Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make bare underscore token an Ident rather than Punct in proc-macro #8122

Merged
merged 2 commits into from
Mar 21, 2021

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
Member

@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

crates/mbe/src/expander/matcher.rs Outdated Show resolved Hide resolved
@edwin0cheng
Copy link
Member

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