Skip to content

Improve error for missing braces in const block #78168

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
camelid opened this issue Oct 20, 2020 · 3 comments · May be fixed by #130751
Open

Improve error for missing braces in const block #78168

camelid opened this issue Oct 20, 2020 · 3 comments · May be fixed by #130751
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@camelid
Copy link
Member

camelid commented Oct 20, 2020

Someone may try to write code like this (playground):

#![allow(incomplete_features)]
#![feature(inline_const)]

fn foo() {
    let x = 2;
    match x {
        const 2 => {}
    }
}

Yet this produces these misleading errors:

   Compiling playground v0.0.1 (/playground)
error: expected identifier, found keyword `const`
 --> src/lib.rs:7:9
  |
7 |         const 2 => {}
  |         ^^^^^ expected identifier, found keyword

error: expected one of `=>`, `@`, `if`, or `|`, found `2`
 --> src/lib.rs:7:15
  |
7 |         const 2 => {}
  |               ^ expected one of `=>`, `@`, `if`, or `|`

error: aborting due to 2 previous errors

error: could not compile `playground`

To learn more, run the command again with --verbose.

Another example (playground):

#![allow(incomplete_features)]
#![feature(inline_const)]

fn foo() {
    let x = const 2;
}

Error:

   Compiling playground v0.0.1 (/playground)
error: expected expression, found keyword `const`
 --> src/lib.rs:5:13
  |
5 |     let x = const 2;
  |             ^^^^^ expected expression

error: aborting due to previous error

error: could not compile `playground`

To learn more, run the command again with --verbose.
@camelid camelid added A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) A-parser Area: The lexing & parsing of Rust source code to an AST labels Oct 20, 2020
@camelid
Copy link
Member Author

camelid commented Oct 20, 2020

I would like to work on this.

@spastorino
Copy link
Member

@camelid 👍, would be happy to review

@JohnTitor JohnTitor added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 21, 2020
@camelid camelid removed their assignment Apr 6, 2021
@GrigorenkoPV
Copy link
Contributor

@rustbot claim

@GrigorenkoPV GrigorenkoPV linked a pull request Sep 23, 2024 that will close this issue
3 tasks
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Sep 23, 2024
…e, r=jieyouxu

Add more test cases for block-no-opening-brace

Also add FIXME's for rust-lang#80931 & rust-lang#78168
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Sep 23, 2024
…e, r=jieyouxu

Add more test cases for block-no-opening-brace

Also add FIXME's for rust-lang#80931 & rust-lang#78168
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 23, 2024
Rollup merge of rust-lang#130721 - GrigorenkoPV:block-no-opening-brace, r=jieyouxu

Add more test cases for block-no-opening-brace

Also add FIXME's for rust-lang#80931 & rust-lang#78168
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
4 participants