diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-04-05 23:51:43 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-04-05 23:51:43 -0400 |
| commit | 89b364d687b7a3d16fb9553f7b5b0c034c406d91 (patch) | |
| tree | 54e5bab4924318f488d3a81d38d839ee1f1d3d1b /src/libsyntax/parse/parser.rs | |
| parent | e4a62109c9694263002c4c80cd2c13cf7913a15e (diff) | |
| parent | 6a9448b523b95dbc850e856508342644fc17db45 (diff) | |
| download | rust-89b364d687b7a3d16fb9553f7b5b0c034c406d91.tar.gz rust-89b364d687b7a3d16fb9553f7b5b0c034c406d91.zip | |
Rollup merge of #41050 - jseyfried:fix_derive_parsing, r=petrochenkov
macros: fix bug parsing `#[derive]` invocations Fixes #40962 (introduced in #40346). r? @nrc
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8595bfc9f79..0dd2c03acb6 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1767,6 +1767,26 @@ impl<'a> Parser<'a> { }) } + /// Like `parse_path`, but also supports parsing `Word` meta items into paths for back-compat. + /// This is used when parsing derive macro paths in `#[derive]` attributes. + pub fn parse_path_allowing_meta(&mut self, mode: PathStyle) -> PResult<'a, ast::Path> { + let meta_ident = match self.token { + token::Interpolated(ref nt) => match **nt { + token::NtMeta(ref meta) => match meta.node { + ast::MetaItemKind::Word => Some(ast::Ident::with_empty_ctxt(meta.name)), + _ => None, + }, + _ => None, + }, + _ => None, + }; + if let Some(ident) = meta_ident { + self.bump(); + return Ok(ast::Path::from_ident(self.prev_span, ident)); + } + self.parse_path(mode) + } + /// Examples: /// - `a::b<T,U>::c<V,W>` /// - `a::b<T,U>::c(V) -> W` |
