Skip to content

Wrong result after short circuit in const_let #53515

Closed
@dtolnay

Description

@dtolnay

I would expect this program to print true. As of rustc 1.30.0-nightly (33b923f 2018-08-18) it prints false. If you change const fn to fn then it prints true as expected.

#![feature(const_fn, const_let)]

const fn id(condition: bool) -> bool {
    let mut ret = true;

    // If condition is true, we short circuit and ret remains true.
    // If condition is false, we assign ret = false.
    let _ = condition || { ret = false; true };

    ret
}

fn main() {
    println!("{}", id(true));
}

Mentioning @oli-obk.
Mentioning const_let tracking issue #48821.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions