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 range indexes don't work in const eval #73083

Closed
LLFourn opened this issue Jun 7, 2020 · 2 comments
Closed

Array range indexes don't work in const eval #73083

LLFourn opened this issue Jun 7, 2020 · 2 comments
Labels
C-bug Category: This is a bug.

Comments

@LLFourn
Copy link

LLFourn commented Jun 7, 2020

I haven't been able to find any issue dealing with this. It seems that min_const_fn stabilised array indexes but not ranges and ranges don't work.

I tried this code:

const a: [u8; 4] = [1, 2, 3, 4];
const b: &'static u8 = &a[1]; //fine
const c: &'static [u8] = &a[1..3]; //broken

pub fn main() {
    dbg!(b);
}

Error:

   Compiling playground v0.0.1 (/playground)
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
 --> src/main.rs:3:27
  |
3 | const c: &'static [u8] = &a[1..3];
  |                           ^^^^^^^

Meta

$ rustc --version --verbose
rustc 1.46.0-nightly (118b50524 2020-06-06)
binary: rustc
commit-hash: 118b50524b79e565f017e08bce9b90a16c63634f
commit-date: 2020-06-06
host: x86_64-unknown-linux-gnu
release: 1.46.0-nightly
LLVM version: 10.0

@jonas-schievink
Copy link
Contributor

Closing in favor of #67792 / #67794

@robertbastian
Copy link
Contributor

Can this be reopened? Const indexing on array and slice was only implemented for single indices, but there doesn't seem to be a technical reason why this wouldn't work for ranges as well. Currently this requires dropping down to pointers and transmutes, which is pretty messy.

Const traits still haven't landed, and don't seem to be close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants