Skip to content

omit unnecessary casts in static arrays #1674

@spernsteiner

Description

@spernsteiner

c2rust-transpile currently inserts excessive casts when translating large static arrays. For example:

static const uint8_t iv_256[32] = {
    0x6a, 0x09, 0xe6, 0x67, 0xbb, 0x67, 0xae, 0x85,
    0x3c, 0x6e, 0xf3, 0x72, 0xa5, 0x4f, 0xf5, 0x3a,
    0x51, 0x0e, 0x52, 0x7f, 0x9b, 0x05, 0x68, 0x8c,
    0x1f, 0x83, 0xd9, 0xab, 0x5b, 0xe0, 0xcd, 0x19
};
static mut IV_256: [crate::stdlib::Uint8T_0; 32] = [
    0x6a as ::core::ffi::c_int as crate::stdlib::Uint8T_0,
    0x9 as ::core::ffi::c_int as crate::stdlib::Uint8T_0,
    0xe6 as ::core::ffi::c_int as crate::stdlib::Uint8T_0,
    0x67 as ::core::ffi::c_int as crate::stdlib::Uint8T_0,
    // 28 more lines ...
];

These casts are unnecessary because the type of each literal is constrained by the declared type of the static. Removing them would make the code much less verbose and more readable. This could likely be done as a postprocessing pass in c2rust-refactor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions