Skip to content
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

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

Closed
cyrgani opened this issue Aug 3, 2024 · 1 comment · Fixed by #128701
Closed

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

cyrgani opened this issue Aug 3, 2024 · 1 comment · Fixed by #128701
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cyrgani
Copy link
Contributor

cyrgani commented Aug 3, 2024

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

@cyrgani cyrgani added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 3, 2024
@veera-sivarajan
Copy link
Contributor

@rustbot claim

@jieyouxu jieyouxu added the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label Aug 4, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Sep 2, 2024
…bank

Don't Suggest Labeling `const` and `unsafe` Blocks

Fixes rust-lang#128604

Previously, both anonymous constant blocks (E.g. The labeled block
inside `['_'; 'block: { break 'block 1 + 2; }]`) and inline const
blocks (E.g. `const { ... }`) were considered to be the same
kind of blocks. This caused the compiler to incorrectly suggest
labeling both the blocks when only anonymous constant blocks can be
labeled.

This PR adds an other enum variant to `Context` so that both the
blocks can be handled appropriately.

Also, adds some doc comments and removes unnecessary `&mut` in a
couple of places.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Sep 3, 2024
…bank

Don't Suggest Labeling `const` and `unsafe` Blocks

Fixes rust-lang#128604

Previously, both anonymous constant blocks (E.g. The labeled block
inside `['_'; 'block: { break 'block 1 + 2; }]`) and inline const
blocks (E.g. `const { ... }`) were considered to be the same
kind of blocks. This caused the compiler to incorrectly suggest
labeling both the blocks when only anonymous constant blocks can be
labeled.

This PR adds an other enum variant to `Context` so that both the
blocks can be handled appropriately.

Also, adds some doc comments and removes unnecessary `&mut` in a
couple of places.
@bors bors closed this as completed in 51c686f Sep 5, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 5, 2024
Rollup merge of rust-lang#128701 - veera-sivarajan:fix-128604, r=estebank

Don't Suggest Labeling `const` and `unsafe` Blocks

Fixes rust-lang#128604

Previously, both anonymous constant blocks (E.g. The labeled block
inside `['_'; 'block: { break 'block 1 + 2; }]`) and inline const
blocks (E.g. `const { ... }`) were considered to be the same
kind of blocks. This caused the compiler to incorrectly suggest
labeling both the blocks when only anonymous constant blocks can be
labeled.

This PR adds an other enum variant to `Context` so that both the
blocks can be handled appropriately.

Also, adds some doc comments and removes unnecessary `&mut` in a
couple of places.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants