diff options
| author | bors <bors@rust-lang.org> | 2018-01-01 07:21:23 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-01-01 07:21:23 +0000 |
| commit | 1bcc6dc7ea430b7d403a57f60e48b3c3cdfcf562 (patch) | |
| tree | 2073115c9aa906116a5698340385e1aacfca21b4 /src/libsyntax/parse/parser.rs | |
| parent | f3ca88cff7dc397f409f561321ee3c4021c05436 (diff) | |
| parent | 8b4bdc2f3f753e0d0b00ecc892a813e9786621e9 (diff) | |
| download | rust-1bcc6dc7ea430b7d403a57f60e48b3c3cdfcf562.tar.gz rust-1bcc6dc7ea430b7d403a57f60e48b3c3cdfcf562.zip | |
Auto merge of #46895 - ricochet1k:macro-lifetimes, r=jseyfried
Allow lifetimes in macros This is a resurrection of PR #41927 which was a resurrection of #33135, which is intended to fix #34303. In short, this allows macros_rules! to use :lifetime as a matcher to match 'lifetimes. Still to do: - [x] Feature gate
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 1a2146509e3..812e3c4967a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1295,6 +1295,10 @@ impl<'a> Parser<'a> { fn get_label(&mut self) -> ast::Ident { match self.token { token::Lifetime(ref ident) => *ident, + token::Interpolated(ref nt) => match nt.0 { + token::NtLifetime(lifetime) => lifetime.ident, + _ => self.bug("not a lifetime"), + }, _ => self.bug("not a lifetime"), } } @@ -2031,14 +2035,12 @@ impl<'a> Parser<'a> { } /// Parse single lifetime 'a or panic. - fn expect_lifetime(&mut self) -> Lifetime { - match self.token { - token::Lifetime(ident) => { - let ident_span = self.span; - self.bump(); - Lifetime { ident: ident, span: ident_span, id: ast::DUMMY_NODE_ID } - } - _ => self.span_bug(self.span, "not a lifetime") + pub fn expect_lifetime(&mut self) -> Lifetime { + if let Some(lifetime) = self.token.lifetime(self.span) { + self.bump(); + lifetime + } else { + self.span_bug(self.span, "not a lifetime") } } |
