# error[E0080]: it is undefined behavior to cast `bool` to `char`

- **ID:** `rust/e0080-invalid-cast-from-bool-to-char`
- **Domain:** rust
- **Category:** type_error
- **Error Code:** `E0080`
- **Verification:** ai_generated
- **Fix Rate:** 95%

## 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).

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| rustc 1.65.0 | active | — | — |
| rustc 1.70.0 | active | — | — |
| rustc 1.76.0 | active | — | — |

## Workarounds

1. **Use explicit conversion with a match: `let c = if b { '1' } else { '0' };`** (95% success)
   ```
   Use explicit conversion with a match: `let c = if b { '1' } else { '0' };`
   ```
2. **Use `char::from_digit(b as u32, 10).unwrap_or('0')` if you want digit characters.** (90% success)
   ```
   Use `char::from_digit(b as u32, 10).unwrap_or('0')` if you want digit characters.
   ```
3. **Convert to u8 first: `let c = (b as u8 + b'0') as char;` for ASCII digits.** (85% success)
   ```
   Convert to u8 first: `let c = (b as u8 + b'0') as char;` for ASCII digits.
   ```

## Dead Ends

- **** — Rust's as cast is not allowed for bool-to-char because it's UB. The compiler rejects it. (95% fail)
- **** — Transmute is unsafe and still UB. It might compile but is undefined behavior. (80% fail)
- **** — There is no From<bool> impl for char. This won't compile. (90% fail)
