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 {
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(),
}
}
- 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 {