about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-09-18 04:01:51 +0000
committerbors <bors@rust-lang.org>2024-09-18 04:01:51 +0000
commitf6bcd094abe174a218f7cf406e75521be4199f88 (patch)
tree6505fe769ecf4568d5fb8466f19168ce9a0cdb98 /compiler/rustc_parse/src/parser
parent60c3673456cb5eba4d6ac4ed22be179deebb6dcf (diff)
parentc52d58dce1044c896153082272522a1d499e95b0 (diff)
downloadrust-f6bcd094abe174a218f7cf406e75521be4199f88.tar.gz
rust-f6bcd094abe174a218f7cf406e75521be4199f88.zip
Auto merge of #130498 - matthiaskrgr:rollup-tg4d0zi, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #130116 (Implement a Method to Seal `DiagInner`'s Suggestions)
 - #130489 (Ensure that `keyword_ident` lint doesn't trigger on `'r#kw` lifetime)
 - #130491 (more crash tests)
 - #130496 (Fix circular fn_sig queries to correct number of args for methods)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/diagnostics.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs
index bee73c58cb7..fd488cf1d31 100644
--- a/compiler/rustc_parse/src/parser/diagnostics.rs
+++ b/compiler/rustc_parse/src/parser/diagnostics.rs
@@ -16,7 +16,7 @@ use rustc_ast_pretty::pprust;
 use rustc_data_structures::fx::FxHashSet;
 use rustc_errors::{
     pluralize, Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, FatalError, PErr, PResult,
-    Subdiagnostic,
+    Subdiagnostic, Suggestions,
 };
 use rustc_session::errors::ExprParenthesesNeeded;
 use rustc_span::edit_distance::find_best_match_for_name;
@@ -775,7 +775,7 @@ impl<'a> Parser<'a> {
         }
 
         // Check for misspelled keywords if there are no suggestions added to the diagnostic.
-        if err.suggestions.as_ref().is_ok_and(|code_suggestions| code_suggestions.is_empty()) {
+        if matches!(&err.suggestions, Suggestions::Enabled(list) if list.is_empty()) {
             self.check_for_misspelled_kw(&mut err, &expected);
         }
         Err(err)
@@ -803,6 +803,9 @@ impl<'a> Parser<'a> {
             && let Some(misspelled_kw) = find_similar_kw(curr_ident, &expected_keywords)
         {
             err.subdiagnostic(misspelled_kw);
+            // We don't want other suggestions to be added as they are most likely meaningless
+            // when there is a misspelled keyword.
+            err.seal_suggestions();
         } else if let Some((prev_ident, _)) = self.prev_token.ident()
             && !prev_ident.is_used_keyword()
         {
@@ -818,6 +821,9 @@ impl<'a> Parser<'a> {
             // 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
+                // when there is a misspelled keyword.
+                err.seal_suggestions();
             }
         }
     }