rust-analyzer/crates/parser/src
Nathaniel McCallum 943b42f743 parser: fix parsing of trait bound polarity and for-binders
The rustc AST allows both `for<>` binders and `?` polarity
modifiers in trait bounds, but they are parsed in a specific
order and validated for correctness:

  1. `for<>` binder is parsed first.
  2. Polarity modifiers (`?`, `!`) are parsed second.
  3. The parser validates that binders and polarity modifiers
     do not conflict:

```rust
if let Some(binder_span) = binder_span {
    match modifiers.polarity {
        BoundPolarity::Maybe(polarity_span) => {
            // Error: "for<...> binder not allowed with ? polarity"
        }
    }
}
```

This implies:

- `for<> ?Sized` → Valid syntax. Invalid semantics.
- `?for<> Sized` → Invalid syntax.

However, rust-analyzer incorrectly had special-case logic that
allowed `?for<>` as valid syntax. This fix removes that incorrect
special case, making rust-analyzer reject `?for<> Sized` as a
syntax error, matching rustc behavior.

This has caused confusion in other crates (such as syn) which
rely on these files to implement correct syntax evaluation.
2025-08-10 02:21:11 -04:00
..
grammar parser: fix parsing of trait bound polarity and for-binders 2025-08-10 02:21:11 -04:00
syntax_kind Parse for<'a> [const] 2025-07-22 16:24:42 +03:00
tests Fix a case where completion was unable to expand a macro 2024-12-20 13:14:59 +02:00
event.rs cargo fmt 2025-03-15 21:32:01 +01:00
grammar.rs cargo fmt 2025-03-15 21:32:01 +01:00
input.rs cargo clippy --fix 2025-07-31 10:55:10 +02:00
lexed_str.rs Format and bump rustc crates 2025-07-15 17:41:08 +03:00
lib.rs refactor: Reduce codegen burden for SyntaxKind 2025-03-21 12:14:39 +01:00
output.rs fix doc tests 2025-02-27 14:58:46 +01:00
parser.rs Always bump in the parser in err_and_bump() 2025-07-06 03:21:43 +03:00
shortcuts.rs cargo clippy --fix 2025-07-31 10:55:10 +02:00
syntax_kind.rs fix: Fix incorrect expansion of builtin PartialOrd derive 2025-03-21 12:14:39 +01:00
tests.rs Correctly handle #"" in edition <2024 2024-10-27 00:47:13 +03:00
token_set.rs internal: simplify TokenSet implementation 2024-04-15 17:33:09 +03:00