# error[E0308]: mismatched types -- expected `i32`, found `u32`

- **ID:** `rust/e0308-mismatched-types-expected-i32-found-u32`
- **Domain:** rust
- **Category:** type_error
- **Error Code:** `E0308`
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

A value of one integer type is used where a different integer type is expected, due to Rust's strict type system not allowing implicit conversions.

## Version Compatibility

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

## Workarounds

1. **Use explicit conversion with `From` or `TryFrom` traits, e.g., `i32::try_from(u32_val)` and handle the Result.** (95% success)
   ```
   Use explicit conversion with `From` or `TryFrom` traits, e.g., `i32::try_from(u32_val)` and handle the Result.
   ```
2. **If the value is guaranteed to fit, use `as` cast with a comment explaining safety.** (90% success)
   ```
   If the value is guaranteed to fit, use `as` cast with a comment explaining safety.
   ```

## Dead Ends

- **** — `as` cast can silently truncate or wrap, leading to data loss; it's not a clean conversion. (70% fail)
- **** — If the source value is inherently u32 (e.g., from an API), changing the variable type may cause other mismatches. (60% fail)
- **** — Unsafe coercion is dangerous and undefined behavior; it doesn't solve the type mismatch. (95% fail)
