diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2020-03-04 23:37:52 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2020-03-09 12:42:41 +0300 |
| commit | 925e9a2188dcd6e1988ceaa3ab8d64fcdb3d6d1e (patch) | |
| tree | 245d7c2b396a68d2580f9defc4ec04232aef94ba /src/librustc_expand | |
| parent | 2cb0b8582ebbf9784db9cec06fff517badbf4553 (diff) | |
| download | rust-925e9a2188dcd6e1988ceaa3ab8d64fcdb3d6d1e.tar.gz rust-925e9a2188dcd6e1988ceaa3ab8d64fcdb3d6d1e.zip | |
rustc_parse: Use `Token::ident` where possible
Diffstat (limited to 'src/librustc_expand')
| -rw-r--r-- | src/librustc_expand/mbe/macro_parser.rs | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/librustc_expand/mbe/macro_parser.rs b/src/librustc_expand/mbe/macro_parser.rs index d2a5c54aae4..efba3a8ccb1 100644 --- a/src/librustc_expand/mbe/macro_parser.rs +++ b/src/librustc_expand/mbe/macro_parser.rs @@ -750,15 +750,9 @@ pub(super) fn parse_tt(parser: &mut Cow<'_, Parser<'_>>, ms: &[TokenTree]) -> Na /// The token is an identifier, but not `_`. /// We prohibit passing `_` to macros expecting `ident` for now. -fn get_macro_name(token: &Token) -> Option<(Name, bool)> { - match token.kind { - token::Ident(name, is_raw) if name != kw::Underscore => Some((name, is_raw)), - token::Interpolated(ref nt) => match **nt { - token::NtIdent(ident, is_raw) if ident.name != kw::Underscore => { - Some((ident.name, is_raw)) - } - _ => None, - }, +fn get_macro_ident(token: &Token) -> Option<(Ident, bool)> { + match token.ident() { + Some((ident, is_raw)) if ident.name != kw::Underscore => Some((ident, is_raw)), _ => None, } } @@ -783,7 +777,7 @@ fn may_begin_with(token: &Token, name: Name) -> bool { && !token.is_keyword(kw::Let) } sym::ty => token.can_begin_type(), - sym::ident => get_macro_name(token).is_some(), + sym::ident => get_macro_ident(token).is_some(), sym::literal => token.can_begin_literal_or_bool(), sym::vis => match token.kind { // The follow-set of :vis + "priv" keyword + interpolated @@ -888,9 +882,9 @@ fn parse_nt_inner<'a>(p: &mut Parser<'a>, sp: Span, name: Symbol) -> PResult<'a, sym::ty => token::NtTy(p.parse_ty()?), // this could be handled like a token, since it is one sym::ident => { - if let Some((name, is_raw)) = get_macro_name(&p.token) { + if let Some((ident, is_raw)) = get_macro_ident(&p.token) { p.bump(); - token::NtIdent(Ident::new(name, p.normalized_prev_token.span), is_raw) + token::NtIdent(ident, is_raw) } else { let token_str = pprust::token_to_string(&p.token); let msg = &format!("expected ident, found {}", &token_str); |
