From ba0dd8eb026e2dcff27a7ee3b29514a53cc5c1d9 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Wed, 21 Mar 2018 22:38:24 -0700 Subject: in which `!` is suggested for erroneous identifier `not` Impressing confused Python users with magical diagnostics is perhaps worth this not-grossly-unreasonable (only 40ish lines) extra complexity in the parser? Thanks to Vadim Petrochenkov for guidance. This resolves #46836. --- src/libsyntax/parse/token.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/libsyntax/parse/token.rs') diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 6544619af9c..df0ea05005c 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -91,7 +91,7 @@ impl Lit { } } -fn ident_can_begin_expr(ident: ast::Ident, is_raw: bool) -> bool { +pub(crate) fn ident_can_begin_expr(ident: ast::Ident, is_raw: bool) -> bool { let ident_token: Token = Ident(ident, is_raw); !ident_token.is_reserved_ident() || @@ -348,6 +348,15 @@ impl Token { self.lifetime().is_some() } + /// Returns `true` if the token is a identifier whose name is the given + /// string slice. + pub fn is_ident_named(&self, name: &str) -> bool { + match self.ident() { + Some((ident, _)) => ident.name.as_str() == name, + None => false + } + } + /// Returns `true` if the token is a documentation comment. pub fn is_doc_comment(&self) -> bool { match *self { -- cgit 1.4.1-3-g733a5