about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-06-11 10:43:20 +0000
committerbors <bors@rust-lang.org>2018-06-11 10:43:20 +0000
commit13f8d073fe5c87638d9ebe849c5fdd80e87da95a (patch)
tree0d0471bcb122e2d35c2ad951a2555c6f08e3da20 /src/libsyntax
parent18a00bd9855421a74f40a29fcb4dd2e0c8bea59f (diff)
parent987020846ce40ce479df3d62adc47ca4609a5317 (diff)
downloadrust-13f8d073fe5c87638d9ebe849c5fdd80e87da95a.tar.gz
rust-13f8d073fe5c87638d9ebe849c5fdd80e87da95a.zip
Auto merge of #51480 - dtolnay:lifetime, r=kennytm
Enable fall through past $:lifetime matcher

```rust
macro_rules! is_lifetime {
    ($lifetime:lifetime) => { true };
    ($other:tt) => { false };
}

fn main() {
    println!("{}", is_lifetime!('lifetime));
    println!("{}", is_lifetime!(@));
}
```

Before this fix, the `is_lifetime!` invocation would fail to compile with:

```
error: expected a lifetime, found `@`
 --> src/main.rs:8:33
  |
8 |     println!("{}", is_lifetime!(@));
  |                                 ^
```

Fixes #50903.
Fixes #51477.

r? @kennytm
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/tt/macro_parser.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs
index b53d94db27e..fe458fa9977 100644
--- a/src/libsyntax/ext/tt/macro_parser.rs
+++ b/src/libsyntax/ext/tt/macro_parser.rs
@@ -827,6 +827,14 @@ fn may_begin_with(name: &str, token: &Token) -> bool {
             Token::Interpolated(ref nt) => may_be_ident(&nt.0),
             _ => false,
         },
+        "lifetime" => match *token {
+            Token::Lifetime(_) => true,
+            Token::Interpolated(ref nt) => match nt.0 {
+                token::NtLifetime(_) | token::NtTT(_) => true,
+                _ => false,
+            },
+            _ => false,
+        },
         _ => match *token {
             token::CloseDelim(_) => false,
             _ => true,