about summary refs log tree commit diff
path: root/src/tools/rust-analyzer/crates/parser/test_data/generated
diff options
context:
space:
mode:
authorNathaniel McCallum <nathaniel@mccallum.life>2025-08-10 01:38:17 -0400
committerNathaniel McCallum <nathaniel@mccallum.life>2025-08-10 02:21:11 -0400
commit6b8a812aafaad6b0edd04d12569fe43ee1e69eed (patch)
tree3b8e1783bc833916e7fd78de1181dd2c28cb59ce /src/tools/rust-analyzer/crates/parser/test_data/generated
parenteca31528356d9721d9f4dc727da1bda20dfee932 (diff)
downloadrust-6b8a812aafaad6b0edd04d12569fe43ee1e69eed.tar.gz
rust-6b8a812aafaad6b0edd04d12569fe43ee1e69eed.zip
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.
Diffstat (limited to 'src/tools/rust-analyzer/crates/parser/test_data/generated')
-rw-r--r--src/tools/rust-analyzer/crates/parser/test_data/generated/runner.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/parser/test_data/generated/runner.rs b/src/tools/rust-analyzer/crates/parser/test_data/generated/runner.rs
index c642e1a3354..a3cfe64e6e7 100644
--- a/src/tools/rust-analyzer/crates/parser/test_data/generated/runner.rs
+++ b/src/tools/rust-analyzer/crates/parser/test_data/generated/runner.rs
@@ -796,6 +796,12 @@ mod err {
     #[test]
     fn impl_type() { run_and_expect_errors("test_data/parser/inline/err/impl_type.rs"); }
     #[test]
+    fn invalid_question_for_type_trait_bound() {
+        run_and_expect_errors(
+            "test_data/parser/inline/err/invalid_question_for_type_trait_bound.rs",
+        );
+    }
+    #[test]
     fn let_else_right_curly_brace() {
         run_and_expect_errors("test_data/parser/inline/err/let_else_right_curly_brace.rs");
     }