diff options
| author | Zack M. Davis <code@zackmdavis.net> | 2018-03-21 22:38:24 -0700 |
|---|---|---|
| committer | Zack M. Davis <code@zackmdavis.net> | 2018-04-09 08:45:12 -0700 |
| commit | ba0dd8eb026e2dcff27a7ee3b29514a53cc5c1d9 (patch) | |
| tree | 9a992fe239e3ee6c43db7664278841b507d8963e /src/libsyntax/parse/token.rs | |
| parent | 944c4017365e0974e7b8c5b52ce2d267e3ab3e4c (diff) | |
| download | rust-ba0dd8eb026e2dcff27a7ee3b29514a53cc5c1d9.tar.gz rust-ba0dd8eb026e2dcff27a7ee3b29514a53cc5c1d9.zip | |
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.
Diffstat (limited to 'src/libsyntax/parse/token.rs')
| -rw-r--r-- | src/libsyntax/parse/token.rs | 11 |
1 files changed, 10 insertions, 1 deletions
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 { |
