From a833be21626890de406e12f2561d2ffbda4aadb4 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 30 Jan 2020 13:02:06 +0100 Subject: parser: fuse free `fn` parsing together. --- src/libsyntax/token.rs | 8 +++++--- src/libsyntax/util/literal.rs | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/token.rs b/src/libsyntax/token.rs index 3045f147698..862934300e0 100644 --- a/src/libsyntax/token.rs +++ b/src/libsyntax/token.rs @@ -402,12 +402,14 @@ impl Token { /// 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). + /// + /// Keep this in sync with `Lit::from_token`. pub fn can_begin_literal_or_bool(&self) -> bool { match self.kind { Literal(..) | BinOp(Minus) => true, Ident(name, false) if name.is_bool_lit() => true, - Interpolated(ref nt) => match **nt { - NtLiteral(..) => true, + Interpolated(ref nt) => match &**nt { + NtExpr(e) | NtLiteral(e) => matches!(e.kind, ast::ExprKind::Lit(_)), _ => false, }, _ => false, @@ -530,7 +532,7 @@ impl Token { } /// Returns `true` if the token is a non-raw identifier for which `pred` holds. - fn is_non_raw_ident_where(&self, pred: impl FnOnce(ast::Ident) -> bool) -> bool { + pub fn is_non_raw_ident_where(&self, pred: impl FnOnce(ast::Ident) -> bool) -> bool { match self.ident() { Some((id, false)) => pred(id), _ => false, diff --git a/src/libsyntax/util/literal.rs b/src/libsyntax/util/literal.rs index dd06c25b4de..0c611adc06b 100644 --- a/src/libsyntax/util/literal.rs +++ b/src/libsyntax/util/literal.rs @@ -188,6 +188,8 @@ impl Lit { } /// Converts arbitrary token into an AST literal. + /// + /// Keep this in sync with `Token::can_begin_literal_or_bool`. pub fn from_token(token: &Token) -> Result { let lit = match token.kind { token::Ident(name, false) if name.is_bool_lit() => { -- cgit 1.4.1-3-g733a5