-
Notifications
You must be signed in to change notification settings - Fork 900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrectly strips r# prefix from labels #6411
Comments
@Raspberry1111 thanks for the report. Has it always been possible to use |
Judging from this pull request: rust-lang/rust#126452 they were added in version Testing this with error: expected `while`, `for`, `loop` or `{` after a label
--> test.rs:4:7
|
4 | 'r#if: {
| ^ expected `while`, `for`, `loop` or `{` after a label
|
help: add `'` to close the char literal
|
4 | 'r'#if: {
| +
error: expected one of `.`, `:`, `;`, `?`, `for`, `loop`, `while`, `}`, or an operator, found `#`
--> test.rs:4:7
|
4 | 'r#if: {
| ^ expected one of 9 possible tokens
error: expected `while`, `for`, `loop` or `{` after a label
--> test.rs:10:7
|
10 | 'r#a: {
| ^ expected `while`, `for`, `loop` or `{` after a label
|
help: add `'` to close the char literal
|
10 | 'r'#a: {
| +
error: expected one of `.`, `:`, `;`, `?`, `for`, `loop`, `while`, `}`, or an operator, found `#`
--> test.rs:10:7
|
10 | 'r#a: {
| ^ expected one of 9 possible tokens
error: aborting due to 4 previous errors Running |
Thanks for the extra info. Yeah, I can reproduce this using the latest commit 9f8fcc2, and running rustfmt from source with input: fn broken() {
'r#if: {
break 'r#if;
}
}
fn works() {
'r#a: {
break 'r#a;
}
} output: fn broken() {
'r#if: {
break 'if;
}
}
fn works() {
'r#a: {
break 'a;
}
} Looks like Lines 201 to 213 in 9f8fcc2
|
@rustbot claim |
@sobatha that's great! Let me know if you need any help getting started. |
Rust playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=051766b3584e787d3abab1d2f18424bb
The following code:
when run through either stable or nightly rustfmt will incorrectly be formatted into this:
which rustc will complain because
'if
is an invalid label name:Note that this still does occur if the label name is not a keyword:
is formatted into
However this does not cause an error.
Versions of
rustfmt
(from rust-playground)1.8.0-stable (2024-11-26 90b35a6239)
and
1.8.0-nightly (2024-11-30 7442931d49)
The text was updated successfully, but these errors were encountered: