diff options
| author | rleungx <rleungx@gmail.com> | 2018-05-03 19:09:34 +0800 |
|---|---|---|
| committer | rleungx <rleungx@gmail.com> | 2018-05-03 19:12:39 +0800 |
| commit | 390c3cee6a8e0c0550eb6213c0e7e5f74c4fbc31 (patch) | |
| tree | 110c99e429502761762734846a6c91488a67ef46 /src/libsyntax/ext/tt | |
| parent | 698b956a9fca9688632d617dd6d73cae834237a3 (diff) | |
| download | rust-390c3cee6a8e0c0550eb6213c0e7e5f74c4fbc31.tar.gz rust-390c3cee6a8e0c0550eb6213c0e7e5f74c4fbc31.zip | |
check if the token is a lifetime before parsing
Diffstat (limited to 'src/libsyntax/ext/tt')
| -rw-r--r-- | src/libsyntax/ext/tt/macro_parser.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index d9c3deb30da..71634ada894 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -835,7 +835,13 @@ fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal { "path" => token::NtPath(panictry!(p.parse_path_common(PathStyle::Type, false))), "meta" => token::NtMeta(panictry!(p.parse_meta_item())), "vis" => token::NtVis(panictry!(p.parse_visibility(true))), - "lifetime" => token::NtLifetime(p.expect_lifetime().ident), + "lifetime" => if p.check_lifetime() { + token::NtLifetime(p.expect_lifetime().ident) + } else { + let token_str = pprust::token_to_string(&p.token); + p.fatal(&format!("expected a lifetime, found `{}`", &token_str)).emit(); + FatalError.raise(); + } // this is not supposed to happen, since it has been checked // when compiling the macro. _ => p.span_bug(sp, "invalid fragment specifier"), |
