Skip to content

Can't call .len() on an array #329

@Jasper-Bekkers

Description

@Jasper-Bekkers

Compiling this gives the following compilation errors.

const OFFSETS : [f32; 18] = [0.000000, 1.494118, 3.486275, 5.478431, 7.470588, 9.462745, 11.454902, 13.447059, 15.439216, 17.431373, 19.423529, 21.415686, 23.407843, 25.400000, 27.392157, 29.384314, 31.376471, 33.368627];

#[allow(unused_attributes)]
#[spirv(fragment)]
pub fn ps_main(
) {
    OFFSETS.len();
}

Errors:

error: Cannot cast between pointer types
  --> C:\Users\Jasper\.rustup\toolchains\nightly-2020-11-24-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\slice\mod.rs:95:18
   |
95 |         unsafe { crate::ptr::Repr { rust: self }.raw.len }
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: from: *{Function} [u8; 8]
   = note: to: *{Function} struct *const [f32] { *{Function} [f32], u32 }

error: Cannot cast between pointer types
  --> C:\Users\Jasper\.rustup\toolchains\nightly-2020-11-24-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\slice\mod.rs:95:18
   |
95 |         unsafe { crate::ptr::Repr { rust: self }.raw.len }
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: from: *{Function} [u8; 8]
   = note: to: *{Function} struct core::ptr::FatPtr<f32> { *{Function} f32, u32 }

error: Cannot cast between pointer types
 --> src\guassian.rs:8:5
  |
8 |     OFFSETS.len();
  |     ^^^^^^^
  |
  = note: from: *{Function} [f32; 18]
  = note: to: *{Function} [f32]

error: aborting due to 3 previous errors; 1 warning emitted

Obviously this can be worked around by just hardcoding the length directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    t: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions