diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-12-13 21:07:58 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-12-18 20:21:03 +1100 |
| commit | 1564318482e80152d43150fdfc3ade2c868f2677 (patch) | |
| tree | 77d53bdb39cd2de362ffe88281af4bdbda27acc5 /compiler/rustc_parse/src | |
| parent | 64abe8be33326643bcc32e25e4c6aaf3555e145b (diff) | |
| download | rust-1564318482e80152d43150fdfc3ade2c868f2677.tar.gz rust-1564318482e80152d43150fdfc3ade2c868f2677.zip | |
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.
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 9b335df6c0f..8417701ac0c 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -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 |
