Skip to content

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

Closed
@LLFourn

Description

@LLFourn

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions