Skip to content

Transmute doesn't work on arrays of generic types #80899

Closed
@mbartlett21

Description

@mbartlett21

I tried transmuting an array of [T; 10] to itself, but rustc gives an error.

fn transmute_to_self<T: Sized>(v: [T; 10]) -> [T; 10] {
    unsafe { core::mem::transmute(v) }
}

Error:

error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
 --> src/lib.rs:4:14
  |
4 |     unsafe { transmute(v) }
  |              ^^^^^^^^^
  |
  = note: `[T; 10]` does not have a fixed size

Meta

rustc --version --verbose:

rustc 1.51.0-nightly (e22670468 2020-12-30)
binary: rustc
commit-hash: e2267046859c9ceb932abc983561d53a117089f6
commit-date: 2020-12-30
host: x86_64-pc-windows-msvc
release: 1.51.0-nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions