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

casting in a static breaks type inference #17756

Closed
porglezomp opened this issue Oct 3, 2014 · 3 comments
Closed

casting in a static breaks type inference #17756

porglezomp opened this issue Oct 3, 2014 · 3 comments
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@porglezomp
Copy link
Contributor

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.

@mahkoh
Copy link
Contributor

mahkoh commented Oct 4, 2014

See rust-lang/rfcs#259

@huonw huonw added the I-wrong label Oct 4, 2014
@arielb1
Copy link
Contributor

arielb1 commented Jun 29, 2015

This works on 1.1+:

const count : usize = 2 as usize;
fn main() {
    let larger : [usize; count*2];
}

@arielb1 arielb1 added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed I-wrong labels Jun 29, 2015
frewsxcv added a commit to frewsxcv/rust that referenced this issue Jun 30, 2015
@frewsxcv
Copy link
Member

Regression test added in #26668

RalfJung pushed a commit to RalfJung/rust that referenced this issue Aug 1, 2024
docs: Fix JSON example for rust-analyzer.workspace.discoverConfig

The user does not specify `{arg}` in their JSON, and be pedantic about commas in JSON sample.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

No branches or pull requests

5 participants