Skip to content
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

Array length during initialization can't be a static #17958

Closed
pdovy opened this issue Oct 11, 2014 · 2 comments
Closed

Array length during initialization can't be a static #17958

pdovy opened this issue Oct 11, 2014 · 2 comments

Comments

@pdovy
Copy link

pdovy commented Oct 11, 2014

In 0.12 the following code is valid:

static ARRAYLEN: uint = 5;

fn main() {
    let x: [u8, ..ARRAYLEN] = [0, ..ARRAYLEN];
}

However in the current nightly build, rustc gives this error:

arraytest.rs:4:12: 4:28 error: expected constant expr for vector length: non-constant path in constant expr
arraytest.rs:4     let x: [u8, ..ARRAYLEN] = [0, ..ARRAYLEN];

This seems like a regression, since ARRAYLEN has an immutable value known at compile time, it should be possible to use it to initialize an array.

@mahkoh
Copy link
Contributor

mahkoh commented Oct 11, 2014

Replace static by const.

@pdovy
Copy link
Author

pdovy commented Oct 11, 2014

Thanks @mahkoh, I didn't realize the syntax had changed. Closing this.

@pdovy pdovy closed this as completed Oct 11, 2014
lnicola pushed a commit to lnicola/rust that referenced this issue Aug 29, 2024
…s, r=Veykril

fix: Fix trait method completions not acknowledging Deref impls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants