-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
While playing with labels in Rust, I noticed that labeled loops can be used as expressions, but aren't parsed correctly after break
:
// This is OK:
let a = 'first_loop: loop {
break 'first_loop 1;
};
// This isn't:
let b = loop {
// Note the colon after 'inner_loop.
break 'inner_loop: loop {
break 'inner_loop 1;
};
};
Output:
error: expected identifier, found keyword `loop`
--> src\main.rs:9:28
|
9 | break 'inner_loop: loop {
| ^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
|
9 | break 'inner_loop: r#loop {
| ^^^^^^
error: expected type, found keyword `loop`
--> src\main.rs:9:28
|
9 | break 'inner_loop: loop {
| - ^^^^ expected type
| |
| help: maybe write a path separator here: `::`
error: aborting due to 2 previous errors
This only happens when the label comes immediately after break
, so this does compile:
loop {
break ('inner: loop {
break 'inner 1;
});
};
loop {
break 1 + 'inner: loop {
break 'inner 1;
};
};
'outer: loop {
break 'outer 'inner: loop {
break 'inner 1;
};
};
Meta
rustc --version --verbose
:
rustc 1.53.0 (53cb7b09b 2021-06-17)
binary: rustc
commit-hash: 53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b
commit-date: 2021-06-17
host: x86_64-pc-windows-gnu
release: 1.53.0
LLVM version: 12.0.1
(The same thing happened on all the platforms and versions I have tried.)
Metadata
Metadata
Assignees
Labels
A-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.