Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sdleffler opened this issue Jan 21, 2016 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@sdleffler
Copy link
Contributor

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.

@nagisa
Copy link
Member

nagisa commented Jan 21, 2016

You cannot use constant expressions in type context either. (apparently I misremembered and confused it with some other thing) I agree, though, that the error message is pretty bad.

@nagisa nagisa added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 21, 2016
@oli-obk
Copy link
Contributor

oli-obk commented Jan 23, 2016

@oli-obk
Copy link
Contributor

oli-obk commented Jan 23, 2016

dupe of #24414

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

4 participants