Skip to content

Uninformative error message for use of non-const expression in fixed-size array type #31082

Closed
@sdleffler

Description

@sdleffler

I was messing with macros and came across the error message "error: no type for local variable 10 [E0513]". The following code will reproduce the error using the Rust playground, on Stable, Beta, and Nightly channels:

fn main() {
    let v: usize = 2;
    let x: [i32; v] = [0, 1];
}

I would have expected an error message such as "expected constant expression, found non-constant expression." It looks like an easy fix, but I imagine E0513 can occur in other situations as well. Replacing let v: usize in the above code sample with const v: usize will compile and run just fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions