# error[E0512]: cannot transmute between types of different sizes, or dependently-sized types

- **ID:** `rust/e0512-cannot-transmute-different-sizes`
- **Domain:** rust
- **Category:** type_error
- **Error Code:** `E0512`
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

Using `std::mem::transmute` to convert between types with mismatched sizes (e.g., `u32` to `u64`).

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.64.0 | active | — | — |
| 1.67.0 | active | — | — |
| 1.71.0 | active | — | — |

## Workarounds

1. **Use safe conversions: `u64::from(u32_val)` or `u32_val as u64` for numeric widening.** (95% success)
   ```
   Use safe conversions: `u64::from(u32_val)` or `u32_val as u64` for numeric widening.
   ```
2. **For structs, use `bytemuck::cast` or `unsafe { transmute_copy }` with explicit size checks.** (80% success)
   ```
   For structs, use `bytemuck::cast` or `unsafe { transmute_copy }` with explicit size checks.
   ```

## Dead Ends

- **Using `unsafe { transmute::<u32, u64>(val) }` without checking size** — Compiler catches size mismatch; transmute requires same layout and size. (100% fail)
- **Adding `#[repr(C)]` to custom types without ensuring alignment** — Doesn't change the size; only affects layout, not total byte count. (90% fail)
