Skip to content

Using an array as a slice causes a compiler error #465

Open

Description

@schell

I'm surprised I haven't hit this earlier, but it's not possible to pass an array as a slice. Is this a known limitation? Is there an easy workaround?

Expected Behaviour

I would expect to be able to pass an array like [u32; 3] as a parameter to a function that takes a slice.

Example & Steps To Reproduce

Here is a minimal reproducible example:

#![no_std]
#![allow(unexpected_cfgs)]

fn do_work(data: &[u32], slab: &mut [u32]) {
    slab[0] = data[0];
    slab[1] = data[1];
    slab[2] = data[2];
}

#[spirv(compute(threads(16)))]
pub fn compute_shader(
    #[spirv(storage_buffer, descriptor_set = 0, binding = 0)] slab: &mut [u32],
    #[spirv(global_invocation_id)] global_id: glam::UVec3,
) {
    let data = [global_id.x, global_id.y, global_id.z];
    do_work(&data, slab);
}

System Info

  • Rustc version: 1.90
  • spirv-std: from the latest main, b3eda4df9814b6176d3c0844eb67f70a22ebb378 as of this writing
  • SPIR-V version:
    ❯ spirv-val --version
    SPIRV-Tools v2025.3 unknown hash, 2025-06-23T19:59:33+00:00
    Targets:
      SPIR-V 1.0
      SPIR-V 1.1
      SPIR-V 1.2
      SPIR-V 1.3
      SPIR-V 1.4
      SPIR-V 1.5
      SPIR-V 1.6
      SPIR-V 1.2 (under OpenCL 2.2 Full Profile semantics)
      SPIR-V 1.0 (under Vulkan 1.0 semantics)
      SPIR-V 1.3 (under Vulkan 1.1 semantics)
      SPIR-V 1.4 (under Vulkan 1.1 semantics)
      SPIR-V 1.5 (under Vulkan 1.2 semantics)
      SPIR-V 1.6 (under Vulkan 1.3 semantics) SPIR-V 1.6 (under Vulkan 1.4 semantics)
    

Activity

  1. changed the title [-]Using an array as a slice causes compiler error[/-] [+]Using an array as a slice causes a compiler error[/+] on Nov 18, 2025
  2. schell commented on Nov 18, 2025

    @schell
    ContributorAuthor

    I should note that if you instead pass data: &[u32; 3] this compiles.

  3. nazar-pc commented on Nov 19, 2025

    @nazar-pc
    Contributor

    You're hitting one of the incarnations of #241

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions