Skip to content

index is not an integer constant expression when using const fn argument #29798

Closed
@oli-obk

Description

@oli-obk
#![feature(const_fn)]
const fn test(x: usize) -> i32 {
    [42;5][x]
}
fn main () {
    let _ = test(5);
}

I guess we cannot const evaluate the index anymore but must translate it with llvm's constant evaluator, because it might only be available as a value we got from a static. But then I'm not sure how to do the range check.

Nope, that's not a problem. Is there any reason not to thin out trans/consts down to the point where it's just a thin wrapper around const_eval + translation of ConstVal to ValueRef?

I mean after #25570 (const indexing), since after that I think the const_eval is feature-equivalent with the const translator.

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.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions