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
This commit is contained in:
bors 2018-01-01 07:21:23 +00:00
commit 1bcc6dc7ea
15 changed files with 231 additions and 21 deletions

View file

@ -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")
}
}