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

const indexing broken in nightly with bit shift (<<) #30226

Closed
Johnson-A opened this issue Dec 5, 2015 · 7 comments
Closed

const indexing broken in nightly with bit shift (<<) #30226

Johnson-A opened this issue Dec 5, 2015 · 7 comments
Labels
regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.

Comments

@Johnson-A
Copy link

const index: usize = 1;

fn main() {
    let array = [1,2,3];
    let test = 1 + array[index]; // This works fine
    let error = 1 << array[index]; // error: const indexing is an unstable feature
}

For some reason, indexing an array with a const requires an unstable feature when there is a bit shift operator. help: in Nightly builds, add #![feature(const_indexing)] to the crate attributes to enable. When adding the feature, there are no more errors but this feature shouldn't be necessary.

rustc 1.6.0-nightly (d49e365 2015-12-05)

@sfackler sfackler added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Dec 5, 2015
@eddyb
Copy link
Member

eddyb commented Dec 6, 2015

What's happening here is that there are const evaluations attempted to determine whether the shift is statically known to be overly long (array[index] >= 32, presumably), and that's hitting the const_indexing feature-gate without actually being in an explicit const context.
cc @oli-obk

@bluss
Copy link
Member

bluss commented Dec 6, 2015

This is the fix: #30202

@frewsxcv
Copy link
Member

frewsxcv commented Dec 8, 2015

This can be closed?

@bluss
Copy link
Member

bluss commented Dec 8, 2015

Yep, the issue is fixed and has tests. Fixed in #30202.

@bluss bluss closed this as completed Dec 8, 2015
@Johnson-A
Copy link
Author

I still get the same compiler error using the latest nightly, however, it looks like the fix has already been merged

@mitaa
Copy link
Contributor

mitaa commented Dec 8, 2015

On the current nightly, rustc --version outputs for me rustc 1.6.0-nightly (aad4e5665 2015-12-05)

This does not yet include the fix.

@oli-obk
Copy link
Contributor

oli-obk commented Dec 8, 2015

it was merged yesterday, so it should probably be in today's nightly (2015-12-08)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

No branches or pull requests

7 participants