1
Fork 0

Rollup merge of #41050 - jseyfried:fix_derive_parsing, r=petrochenkov

macros: fix bug parsing `#[derive]` invocations

Fixes #40962 (introduced in #40346).
r? @nrc
This commit is contained in:
Corey Farwell 2017-04-05 23:51:43 -04:00 committed by GitHub
commit 89b364d687
4 changed files with 46 additions and 3 deletions

View file

@ -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`