diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2025-02-19 17:26:03 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2025-02-19 17:26:13 +0000 |
| commit | a090e76dab39b3771b5e99096766b5ffac588145 (patch) | |
| tree | 429385c2977fcc1ae8ef17bed15ae36460a551bf /tests | |
| parent | d88ffcdb8bfc6f8b917574c1693eb9764a20eff5 (diff) | |
| download | rust-a090e76dab39b3771b5e99096766b5ffac588145.tar.gz rust-a090e76dab39b3771b5e99096766b5ffac588145.zip | |
Tweak "expected ident" parse error to avoid talking about doc comments
When encountering a doc comment without an identifier after, we'd unconditionally state "this doc comment doesn't document anything", swallowing the *actual* error which is that the thing *after* the doc comment wasn't expected. Added a check that the found token is something that "conceptually" closes the previous item before emitting that error, otherwise just complain about the missing identifier.
In both of the following cases, the syntax error follows a doc comment:
```
error: expected identifier, found keyword `Self`
--> $DIR/doc-before-bad-variant.rs:4:5
|
LL | enum TestEnum {
| -------- while parsing this enum
...
LL | Self,
| ^^^^ expected identifier, found keyword
|
= help: enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`
```
```
error: expected identifier, found `<`
--> $DIR/doc-before-syntax-error.rs:2:1
|
LL | <>
| ^ expected identifier
```
Fix #71982.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/parser/doc-before-bad-variant.rs | 6 | ||||
| -rw-r--r-- | tests/ui/parser/doc-before-bad-variant.stderr | 13 | ||||
| -rw-r--r-- | tests/ui/parser/doc-before-syntax-error.rs | 2 | ||||
| -rw-r--r-- | tests/ui/parser/doc-before-syntax-error.stderr | 8 |
4 files changed, 29 insertions, 0 deletions
diff --git a/tests/ui/parser/doc-before-bad-variant.rs b/tests/ui/parser/doc-before-bad-variant.rs new file mode 100644 index 00000000000..bfede28c108 --- /dev/null +++ b/tests/ui/parser/doc-before-bad-variant.rs @@ -0,0 +1,6 @@ +enum TestEnum { + Works, + /// Some documentation + Self, //~ ERROR expected identifier, found keyword `Self` + //~^ HELP enum variants can be +} diff --git a/tests/ui/parser/doc-before-bad-variant.stderr b/tests/ui/parser/doc-before-bad-variant.stderr new file mode 100644 index 00000000000..5e4d4116f25 --- /dev/null +++ b/tests/ui/parser/doc-before-bad-variant.stderr @@ -0,0 +1,13 @@ +error: expected identifier, found keyword `Self` + --> $DIR/doc-before-bad-variant.rs:4:5 + | +LL | enum TestEnum { + | -------- while parsing this enum +... +LL | Self, + | ^^^^ expected identifier, found keyword + | + = help: enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }` + +error: aborting due to 1 previous error + diff --git a/tests/ui/parser/doc-before-syntax-error.rs b/tests/ui/parser/doc-before-syntax-error.rs new file mode 100644 index 00000000000..435f497d186 --- /dev/null +++ b/tests/ui/parser/doc-before-syntax-error.rs @@ -0,0 +1,2 @@ +/// Some documentation +<> //~ ERROR expected identifier diff --git a/tests/ui/parser/doc-before-syntax-error.stderr b/tests/ui/parser/doc-before-syntax-error.stderr new file mode 100644 index 00000000000..93e39d63000 --- /dev/null +++ b/tests/ui/parser/doc-before-syntax-error.stderr @@ -0,0 +1,8 @@ +error: expected identifier, found `<` + --> $DIR/doc-before-syntax-error.rs:2:1 + | +LL | <> + | ^ expected identifier + +error: aborting due to 1 previous error + |
