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.
This commit is contained in:
parent
944c401736
commit
ba0dd8eb02
4 changed files with 146 additions and 2 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue