Const generics: Generic array transmutes do not work (still)
Open
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)
Originally posted by @nazar-pc in #61956
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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