{
  "id": "rust/e0080-invalid-cast-from-bool-to-char",
  "signature": "error[E0080]: it is undefined behavior to cast `bool` to `char`",
  "signature_zh": "错误[E0080]：将 `bool` 转换为 `char` 是未定义行为",
  "regex": "error\\[E0080\\]: it is undefined behavior to cast `bool` to `char`",
  "domain": "rust",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Casting a bool to char is undefined behavior because bool has values 0 and 1, but char requires valid Unicode scalar values (0x0 to 0x10FFFF, excluding surrogates).",
  "root_cause_type": "generic",
  "root_cause_zh": "将 bool 转换为 char 是未定义行为，因为 bool 只有值 0 和 1，但 char 要求有效的 Unicode 标量值（0x0 到 0x10FFFF，不包括代理项）。",
  "versions": [
    {
      "version": "rustc 1.65.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "rustc 1.70.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "rustc 1.76.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Rust's as cast is not allowed for bool-to-char because it's UB. The compiler rejects it.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Transmute is unsafe and still UB. It might compile but is undefined behavior.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "There is no From<bool> impl for char. This won't compile.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use explicit conversion with a match: `let c = if b { '1' } else { '0' };`",
      "success_rate": 0.95,
      "how": "Use explicit conversion with a match: `let c = if b { '1' } else { '0' };`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use `char::from_digit(b as u32, 10).unwrap_or('0')` if you want digit characters.",
      "success_rate": 0.9,
      "how": "Use `char::from_digit(b as u32, 10).unwrap_or('0')` if you want digit characters.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Convert to u8 first: `let c = (b as u8 + b'0') as char;` for ASCII digits.",
      "success_rate": 0.85,
      "how": "Convert to u8 first: `let c = (b as u8 + b'0') as char;` for ASCII digits.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "使用 match 进行显式转换：`let c = if b { '1' } else { '0' };`",
    "使用 `char::from_digit(b as u32, 10).unwrap_or('0')` 获取数字字符。",
    "先转换为 u8：`let c = (b as u8 + b'0') as char;` 用于 ASCII 数字。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://doc.rust-lang.org/error_codes/E0080.html",
  "official_doc_section": null,
  "error_code": "E0080",
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-08-22",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}