Only have one source of truth for keywords.
`rustc_symbol` is the source of truth for keywords. rustdoc has its own implicit definition of keywords, via the `is_doc_keyword`. It (presumably) intends to include all keywords, but it omits `yeet`. rustfmt has its own explicit list of Rust keywords. It also (presumably) intends to include all keywords, but it omits `await`, `builtin`, `gen`, `macro_rules`, `raw`, `reuse`, `safe`, and `yeet`. Also, it does linear searches through this list, which is inefficient. This commit fixes all of the above problems by introducing a new predicate `is_any_keyword` in rustc and using it in rustdoc and rustfmt. It documents that it's not the right predicate in most cases.
This commit is contained in:
parent
64abe8be33
commit
1564318482
4 changed files with 31 additions and 78 deletions
|
@ -815,8 +815,8 @@ impl<'a> Parser<'a> {
|
|||
|
||||
// Otherwise, check the previous token with all the keywords as possible candidates.
|
||||
// This handles code like `Struct Human;` and `While a < b {}`.
|
||||
// We check the previous token only when the current token is an identifier to avoid false
|
||||
// positives like suggesting keyword `for` for `extern crate foo {}`.
|
||||
// We check the previous token only when the current token is an identifier to avoid
|
||||
// false positives like suggesting keyword `for` for `extern crate foo {}`.
|
||||
if let Some(misspelled_kw) = find_similar_kw(prev_ident, &all_keywords) {
|
||||
err.subdiagnostic(misspelled_kw);
|
||||
// We don't want other suggestions to be added as they are most likely meaningless
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue