Uh oh!
There was an error while loading. Please reload this page.
rust-analyzer: fix parsing of trait bound polarity and for-binders - #145199
rust-analyzer: fix parsing of trait bound polarity and for-binders#145199npmccallum wants to merge 1 commit into
Conversation
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.rustbot
commented
Aug 10, 2025
rustbot has assigned @Mark-Simulacrum. Use |
rustbot
commented
Aug 10, 2025
rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead. cc @rust-lang/rust-analyzer |
jieyouxu
commented
Aug 10, 2025
This is a r-a-only change, so please instead submit this PR against the r-a repository. |
npmccallum
commented
Aug 10, 2025
I don't think this is true. I think my commit message just triggered the bot. This is a change to the parser crate which is hosted in this repo. I'm not sure the best way to improve my commit message. |
To clarify, rust-analyzer is a subtree of this repository, but it is not a git submodule (because that has annoying UX issue). It is in fact sync'd between this repo and rust-analyzer with https://github.com/rust-lang/josh-sync. You can see an example sync such as #144887. Please refer to https://rustc-dev-guide.rust-lang.org/external-repos.html?highlight=josh#external-dependencies-subtrees. I.e. the bot message is correct. |
jieyouxu
commented
Aug 10, 2025
In any case, I'll roll a rust-analyzer reviewer, if the r-a reviewer is fine reviewing/accepting it on the r-l/r repo side then disregard the above. r? rust-analyzer |
ChayimFriedman2
commented
Aug 10, 2025
Please send rust-analyzer-only PRs to https://github.com/rust-lang/rust-analyzer/. |
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: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<> Sizedas 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.