Skip to content

Conversation

A4-Tacks
Copy link
Contributor

@A4-Tacks A4-Tacks commented Oct 6, 2025

Example

static C<i32>: u32 = 0;

->

-error 8: missing type for `const` or `static`
+error 8: `static` may not have generic parameters

const C = 0;

->

-error 7: missing type for `const` or `static`
+error 7: missing type for `const`

static C = 0;

->

-error 8: missing type for `const` or `static`
+error 8: missing type for `static`

Example
---
```rust
static C<i32>: u32 = 0;
```
->
```diff
-error 8: missing type for `const` or `static`
+error 8: `static` may not have generic parameters
```

---

```rust
const C = 0;
```
->
```diff
-error 7: missing type for `const` or `static`
+error 7: missing type for `const`
```

---

```rust
static C = 0;
```
->
```diff
-error 8: missing type for `const` or `static`
+error 8: missing type for `static`
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 6, 2025
Copy link
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't invest too much in our errors currently, but this doesn't harm.

// }
generic_params::opt_generic_param_list(p);
} else if p.at(T![<]) {
p.error("`static` may not have generic parameters");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's preferable to eat generic params here, or even better, call opt_generic_params() unconditionally, and just err before for statics. This will also allow us to simplify the next if.

Copy link
Contributor Author

@A4-Tacks A4-Tacks Oct 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the AST of a static item contain GENERIC_PARAM_LIST?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It causes no harm.

Copy link
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Oct 9, 2025
Merged via the queue into rust-lang:master with commit f8fdf54 Oct 9, 2025
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 9, 2025
@A4-Tacks A4-Tacks deleted the improve-static-const-parse-error branch October 9, 2025 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants