rust-lang / rust-lang/rust

Const generics: Generic array transmutes do not work (still)

Open
#152,507 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-array A-const-generics needs-triage T-compiler T-lang
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

A trivial variation of https://github.com/rust-lang/rust/issues/61956 still doesn't compile with an identical error:

#[repr(C)]
struct T(u8);

fn silly_default<const N: usize>(arr: [T; N]) -> [u8; N] {
    unsafe { core::mem::transmute::<_, _>(arr) }
}
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
 --> src/lib.rs:5:14
  |
5 |     unsafe { core::mem::transmute::<_, _>(arr) }
  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: source type: `[T; N]` (this type does not have a fixed size)
  = note: target type: `[u8; N]` (this type does not have a fixed size)

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=eb6a2e37b08e65b8b15936a1cd7fa0d7

Originally posted by @nazar-pc in #61956

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducer in src/lib.rs and compare its behavior with rust-lang/rust#61956. Run the linked Rust Playground example to confirm the E0512 diagnostic for the const-generic array transmute. Done means the shown generic function compiles without the current size-related error, with appropriate coverage for the reported case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.