X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibsyntax%2Fparse%2Ftoken.rs;h=6f3da344ccf88e6cc7a5857d809dcef8a3fcda56;hb=1db4d607e7621a7d813743e83125859a47970f79;hp=4a8b25c61079b6ad3bf8384d2c306b726b70078d;hpb=bc85061203da7bf4ce9c795dfe0278c882ab9fea;p=rust.git diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 4a8b25c6107..6f3da344ccf 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -143,34 +143,35 @@ pub fn new(kind: LitKind, symbol: Symbol, suffix: Option) -> Lit { pub(crate) fn ident_can_begin_expr(name: ast::Name, span: Span, is_raw: bool) -> bool { let ident_token = Token::new(Ident(name, is_raw), span); + token_can_begin_expr(&ident_token) +} +pub(crate) fn token_can_begin_expr(ident_token: &Token) -> bool { !ident_token.is_reserved_ident() || ident_token.is_path_segment_keyword() || - [ - kw::Async, - - // FIXME: remove when `await!(..)` syntax is removed - // https://github.com/rust-lang/rust/issues/60610 - kw::Await, - - kw::Do, - kw::Box, - kw::Break, - kw::Continue, - kw::False, - kw::For, - kw::If, - kw::Let, - kw::Loop, - kw::Match, - kw::Move, - kw::Return, - kw::True, - kw::Unsafe, - kw::While, - kw::Yield, - kw::Static, - ].contains(&name) + match ident_token.kind { + TokenKind::Ident(ident, _) => [ + kw::Async, + kw::Do, + kw::Box, + kw::Break, + kw::Continue, + kw::False, + kw::For, + kw::If, + kw::Let, + kw::Loop, + kw::Match, + kw::Move, + kw::Return, + kw::True, + kw::Unsafe, + kw::While, + kw::Yield, + kw::Static, + ].contains(&ident), + _=> false, + } } fn ident_can_begin_type(name: ast::Name, span: Span, is_raw: bool) -> bool { @@ -380,9 +381,7 @@ pub fn can_begin_type(&self) -> bool { match self.kind { OpenDelim(Brace) => true, Interpolated(ref nt) => match **nt { - NtExpr(..) => true, - NtBlock(..) => true, - NtLiteral(..) => true, + NtExpr(..) | NtBlock(..) | NtLiteral(..) => true, _ => false, } _ => self.can_begin_literal_or_bool(), @@ -403,13 +402,6 @@ pub fn is_lit(&self) -> bool { } } - crate fn expect_lit(&self) -> Lit { - match self.kind { - Literal(lit) => lit, - _ => panic!("`expect_lit` called on non-literal"), - } - } - /// Returns `true` if the token is any literal, a minus (which can prefix a literal, /// for example a '-42', or one of the boolean idents). pub fn can_begin_literal_or_bool(&self) -> bool {