{
  "id": "rust/e0512-cannot-transmute-different-sizes",
  "signature": "error[E0512]: cannot transmute between types of different sizes, or dependently-sized types",
  "signature_zh": "错误[E0512]：无法在不同大小或依赖大小的类型之间进行 transmute",
  "regex": "error\\[E0512\\]: cannot transmute between types of different sizes, or dependently-sized types",
  "domain": "rust",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Using `std::mem::transmute` to convert between types with mismatched sizes (e.g., `u32` to `u64`).",
  "root_cause_type": "generic",
  "root_cause_zh": "使用 `std::mem::transmute` 在大小不匹配的类型之间进行转换（例如 `u32` 到 `u64`）。",
  "versions": [
    {
      "version": "1.64.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.67.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.71.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using `unsafe { transmute::<u32, u64>(val) }` without checking size",
      "why_fails": "Compiler catches size mismatch; transmute requires same layout and size.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding `#[repr(C)]` to custom types without ensuring alignment",
      "why_fails": "Doesn't change the size; only affects layout, not total byte count.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use safe conversions: `u64::from(u32_val)` or `u32_val as u64` for numeric widening.",
      "success_rate": 0.95,
      "how": "Use safe conversions: `u64::from(u32_val)` or `u32_val as u64` for numeric widening.",
      "condition": "",
      "sources": []
    },
    {
      "action": "For structs, use `bytemuck::cast` or `unsafe { transmute_copy }` with explicit size checks.",
      "success_rate": 0.8,
      "how": "For structs, use `bytemuck::cast` or `unsafe { transmute_copy }` with explicit size checks.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "使用安全转换：`u64::from(u32_val)` 或 `u32_val as u64` 进行数值拓宽。",
    "对于结构体，使用 `bytemuck::cast` 或 `unsafe { transmute_copy }` 并显式检查大小。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://doc.rust-lang.org/error_codes/E0512.html",
  "official_doc_section": null,
  "error_code": "E0512",
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-03-22",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}