Skip to content

Trying to break from a const block gives invalid help message #128604

Closed
@cyrgani

Description

@cyrgani

Code

const _: () = const {
    break;
};

Current output

error[E0268]: `break` outside of a loop or labeled block
 --> src/lib.rs:2:5
  |
2 |     break;
  |     ^^^^^ cannot `break` outside of a loop or labeled block
  |
help: consider labeling this block to be able to break within it
  |
1 ~ const _: () = const 'block: {
2 ~     break 'block;
  |

For more information about this error, try `rustc --explain E0268`.

Desired output

Help suggestion should be removed.

Rationale and extra context

The proposed syntax is invalid:

error: expected expression, found keyword `const`
 --> src/lib.rs:1:15
  |
1 | const _: () = const 'block: {
  |               ^^^^^ expected expression

Other cases

No response

Rust Version

rustc 1.80.0 (051478957 2024-07-21)
binary: rustc
commit-hash: 051478957371ee0084a7c0913941d2a8c4757bb9
commit-date: 2024-07-21
host: x86_64-unknown-linux-gnu
release: 1.80.0
LLVM version: 18.1.7

Anything else?

No response

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions