diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-21 00:10:14 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-21 00:10:14 +0000 |
commit | 787bd3c5516d250245f6070308d689311b638fbe (patch) | |
tree | 3513cb44470b7ff148258bc300402be778c7f097 /crates/mbe/src/expander | |
parent | 090e013161ab5b1679554ddd53683e81e3fe845a (diff) | |
parent | 0a7f28620a7002f47890c2030862052bcbf25cdb (diff) |
Merge #8122
8122: Make bare underscore token an Ident rather than Punct in proc-macro r=edwin0cheng a=kevinmehall
In rustc and proc-macro2, a bare `_` token is parsed for procedural macro purposes as `Ident` rather than `Punct` (see https://github.com/rust-lang/rust/pull/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:
```rust
#[proc_macro]
pub fn input(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
dbg!(input)
}
```
test crate:
```rust
test_proc_macro::input!(_);
```
output (rustc):
```rust
[test-proc-macro/src/lib.rs:10] input = TokenStream [
Ident {
ident: "_",
span: #0 bytes(173..174),
},
]
```
output (rust-analyzer before this change):
```rust
[test-proc-macro/src/lib.rs:10] input = TokenStream [
Punct {
ch: '_',
spacing: Joint,
span: 4294967295,
},
]
```
output (rust-analyzer after this change):
```rust
[test-proc-macro/src/lib.rs:10] input = TokenStream [
Ident {
ident: "_",
span: 4294967295,
},
]
```
Co-authored-by: Kevin Mehall <[email protected]>
Diffstat (limited to 'crates/mbe/src/expander')
-rw-r--r-- | crates/mbe/src/expander/matcher.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/crates/mbe/src/expander/matcher.rs b/crates/mbe/src/expander/matcher.rs index b6782b4ba..1682b21b0 100644 --- a/crates/mbe/src/expander/matcher.rs +++ b/crates/mbe/src/expander/matcher.rs | |||
@@ -762,7 +762,7 @@ impl<'a> TtIter<'a> { | |||
762 | fn expect_separator(&mut self, separator: &Separator, idx: usize) -> bool { | 762 | fn expect_separator(&mut self, separator: &Separator, idx: usize) -> bool { |
763 | let mut fork = self.clone(); | 763 | let mut fork = self.clone(); |
764 | let ok = match separator { | 764 | let ok = match separator { |
765 | Separator::Ident(lhs) if idx == 0 => match fork.expect_ident() { | 765 | Separator::Ident(lhs) if idx == 0 => match fork.expect_ident_or_underscore() { |
766 | Ok(rhs) => rhs.text == lhs.text, | 766 | Ok(rhs) => rhs.text == lhs.text, |
767 | _ => false, | 767 | _ => false, |
768 | }, | 768 | }, |
@@ -852,7 +852,7 @@ impl<'a> TtIter<'a> { | |||
852 | if punct.char != '\'' { | 852 | if punct.char != '\'' { |
853 | return Err(()); | 853 | return Err(()); |
854 | } | 854 | } |
855 | let ident = self.expect_ident()?; | 855 | let ident = self.expect_ident_or_underscore()?; |
856 | 856 | ||
857 | Ok(tt::Subtree { | 857 | Ok(tt::Subtree { |
858 | delimiter: None, | 858 | delimiter: None, |