Skip to content

Let-else not checking for curly brace of inline const before else #118859

Closed
@dtolnay

Description

@dtolnay
#![feature(inline_const)]

fn main() {
    let false = const {
        true
    } else {
        return;
    };
}

I believe the intention in let-else is that this code should be considered syntactically invalid, but it compiles successfully today.

If you replace const with unsafe, it correctly fails to parse.

error: right curly brace `}` before `else` in a `let...else` statement not allowed
 --> src/main.rs:6:5
  |
6 |     } else {
  |     ^
  |
help: wrap the expression in parentheses
  |
4 ~     let false = (unsafe {
5 |         true
6 ~     }) else {
  |

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.F-inline_constInline constants (aka: const blocks, const expressions, anonymous constants)F-let_elseIssues related to let-else statements (RFC 3137)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions