-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.F-inline_constInline constants (aka: const blocks, const expressions, anonymous constants)Inline constants (aka: const blocks, const expressions, anonymous constants)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
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.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.F-inline_constInline constants (aka: const blocks, const expressions, anonymous constants)Inline constants (aka: const blocks, const expressions, anonymous constants)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.
Activity
camelid commentedon Oct 20, 2020
I would like to work on this.
spastorino commentedon Oct 21, 2020
@camelid 👍, would be happy to review
const
block pattern #78173GrigorenkoPV commentedon Sep 23, 2024
@rustbot claim
const
block pattern #130751Rollup merge of rust-lang#130721 - GrigorenkoPV:block-no-opening-brac…
Rollup merge of rust-lang#130721 - GrigorenkoPV:block-no-opening-brac…
Unrolled build for rust-lang#130721