about summary refs log tree commit diff
path: root/compiler/rustc_ast/src
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-06-27 15:04:56 +0200
committerGitHub <noreply@github.com>2025-06-27 15:04:56 +0200
commit8e7b0b57ea97afd31b05709b3da525036269df57 (patch)
treeb565a849e953b15e5df08cfe7ff175d195738eb9 /compiler/rustc_ast/src
parent8e5fd99b33fb60e96f7c7420c39e95d9807b498e (diff)
parent4e51e67a24d940d3c8069062d07f663ee2034ac3 (diff)
downloadrust-8e7b0b57ea97afd31b05709b3da525036269df57.tar.gz
rust-8e7b0b57ea97afd31b05709b3da525036269df57.zip
Rollup merge of #143065 - compiler-errors:enum-recovery, r=oli-obk
Improve recovery when users write `where:`

Improve recovery of `where:`.

Fixes https://github.com/rust-lang/rust/issues/143023

The erroneous suggestion was because we were seeing `:` then a type, which the original impl thought must be a struct field. Make this a bit more accurate by checking for a non-reserved ident (which should be a field name).

Also, make a custom parser error for `where:` so we can continue parsing after the colon.
Diffstat (limited to 'compiler/rustc_ast/src')
-rw-r--r--compiler/rustc_ast/src/token.rs6
-rw-r--r--compiler/rustc_ast/src/tokenstream.rs6
2 files changed, 7 insertions, 5 deletions
diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs
index 9b4535dcfbc..fc816f2cb79 100644
--- a/compiler/rustc_ast/src/token.rs
+++ b/compiler/rustc_ast/src/token.rs
@@ -893,7 +893,7 @@ impl Token {
             || self.is_qpath_start()
             || matches!(self.is_metavar_seq(), Some(MetaVarKind::Path))
             || self.is_path_segment_keyword()
-            || self.is_ident() && !self.is_reserved_ident()
+            || self.is_non_reserved_ident()
     }
 
     /// Returns `true` if the token is a given keyword, `kw`.
@@ -937,6 +937,10 @@ impl Token {
         self.is_non_raw_ident_where(Ident::is_reserved)
     }
 
+    pub fn is_non_reserved_ident(&self) -> bool {
+        self.ident().is_some_and(|(id, raw)| raw == IdentIsRaw::Yes || !Ident::is_reserved(id))
+    }
+
     /// Returns `true` if the token is the identifier `true` or `false`.
     pub fn is_bool_lit(&self) -> bool {
         self.is_non_raw_ident_where(|id| id.name.is_bool_lit())
diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs
index 3c231be20dc..c60185cdde0 100644
--- a/compiler/rustc_ast/src/tokenstream.rs
+++ b/compiler/rustc_ast/src/tokenstream.rs
@@ -634,10 +634,8 @@ impl TokenStream {
                     (
                         TokenTree::Token(token_left, Spacing::Alone),
                         TokenTree::Token(token_right, _),
-                    ) if ((token_left.is_ident() && !token_left.is_reserved_ident())
-                        || token_left.is_lit())
-                        && ((token_right.is_ident() && !token_right.is_reserved_ident())
-                            || token_right.is_lit()) =>
+                    ) if (token_left.is_non_reserved_ident() || token_left.is_lit())
+                        && (token_right.is_non_reserved_ident() || token_right.is_lit()) =>
                     {
                         token_left.span
                     }