Rollup merge of #137140 - Noratrieb:const-move, r=jieyouxu,compiler-errors

Fix const items not being allowed to be called `r#move` or `r#static`

Because of an ambiguity with const closures, the parser needs to ensure that for a const item, the `const` keyword isn't followed by a `move` or `static` keyword, as that would indicate a const closure:

```rust
fn main() {
  const move // ...
}
```

This check did not take raw identifiers into account, therefore being unable to distinguish between `const move` and `const r#move`. The latter is obviously not a const closure, so it should be allowed as a const item.

This fixes the check in the parser to only treat `const ...` as a const closure if it's followed by the *proper keyword*, and not a raw identifier.

Additionally, this adds a large test that tests for all raw identifiers in all kinds of positions, including `const`, to prevent issues like this one from occurring again.

fixes #137128
This commit is contained in:
Matthias Krüger 2025-02-17 06:37:39 +01:00 committed by GitHub
commit f0710999a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 163 additions and 3 deletions

View file

@ -104,6 +104,8 @@ symbols! {
Gen: "gen", // >= 2024 Edition only
Try: "try", // >= 2018 Edition only
// NOTE: When adding new keywords, consider adding them to the ui/parser/raw/raw-idents.rs test.
// "Lifetime keywords": regular keywords with a leading `'`.
// Matching predicates: `is_any_keyword`
UnderscoreLifetime: "'_",