Closed
Description
Writing the following works perfectly:
static count : uint = 2;
fn main() {
let larger : [uint, ..count*2];
}
While the following:
static count : uint = 2 as uint;
fn main() {
let larger : [uint, ..count*2];
}
Fails with error: expected constant expr for vector length: can't do this op on a uint and int
. This looks like a problem with the type inference, and using 2u
fixes this example, but breaks the one that previously worked.
When the array is being initialized rather than having the type set:
let larger = [0u, ..count*2];
The error is a much more cryptic error: expected constant integer for repeat count, found variable
, and which one fails can again be swapped by multiplying by 2u
instead of 2
.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
mahkoh commentedon Oct 4, 2014
See rust-lang/rfcs#259
arielb1 commentedon Jun 29, 2015
This works on 1.1+:
Add regression test for rust-lang#17756
frewsxcv commentedon Jun 30, 2015
Regression test added in #26668
Auto merge of #26668 - frewsxcv:regression-test-17756, r=alexcrichton
Auto merge of rust-lang#17756 - Wilfred:fix_adoc_json, r=Veykril