Repository: swiftlang/swift-syntax (swift)

Issue:
Too much skipping after invalid token in `for` element name
### Issue Kind

Bad Diagnostic Produced

### Source Code

```swift
for var elem? in arr { }
```

### Description

This results diagnostics:
```
test.swift:1:13: error: expected 'in' and expression in 'for' statement
1 │ for var elem? in arr { }
  │             ├─ error: expected 'in' and expression in 'for' statement
  │             ╰─ error: unexpected code '? in arr' in 'for' statement
2 │ 
```
And in the parsed syntax tree `? in arr ` part is parsed as `CodeBlockItemSyntax.unexpectedBeforeLeftBrace`

Pull request description:
Fixed #2406

Patch:
diff --git a/Sources/SwiftParser/TokenPrecedence.swift b/Sources/SwiftParser/TokenPrecedence.swift
index c2d0d708515..fdf8eda3ad7 100644
--- a/Sources/SwiftParser/TokenPrecedence.swift
+++ b/Sources/SwiftParser/TokenPrecedence.swift
@@ -203,9 +203,7 @@ enum TokenPrecedence: Comparable {
       // Consider 'any' a prefix operator to a type and a type is expression-like.
       .Any,
       // 'where' can only occur in the signature of declarations. Consider the signature expression-like.
-      .where,
-      // 'in' occurs in closure input/output definitions and for loops. Consider both constructs expression-like.
-      .in:
+      .where:
       self = .exprKeyword
 
     case  // Control-flow constructs
@@ -213,7 +211,9 @@ enum TokenPrecedence: Comparable {
       // Secondary parts of control-flow constructs
       .case, .catch, .default, .else,
       // Return-like statements
-      .break, .continue, .fallthrough, .return, .throw, .then, .yield:
+      .break, .continue, .fallthrough, .return, .throw, .then, .yield,
+      // 'in' occurs in closure input/output definitions and for loops. Consider both constructs expression-like.
+      .in:
       self = .stmtKeyword
 
     // MARK: Decl keywords


Test patch:
diff --git a/Tests/SwiftParserTest/StatementTests.swift b/Tests/SwiftParserTest/StatementTests.swift
index 394e4af55ed..bd3f790bb75 100644
--- a/Tests/SwiftParserTest/StatementTests.swift
+++ b/Tests/SwiftParserTest/StatementTests.swift
@@ -921,4 +921,13 @@ final class StatementTests: ParserTestCase {
       """
     )
   }
+
+  func testForStatementWithUnexpectedTokenBeforeInKeyword() {
+    assertParse(
+      "for var elem1️⃣? in arr { }",
+      diagnostics: [
+        DiagnosticSpec(message: "unexpected code '?' in 'for' statement")
+      ]
+    )
+  }
 }