# error[E0308]: mismatched types: expected `usize`, found `f64`

- **ID:** `rust/e0308-expected-usize-found-float`
- **Domain:** rust
- **Category:** type_error
- **Error Code:** `E0308`
- **Verification:** ai_generated
- **Fix Rate:** 92%

## Root Cause

Assigning or passing a floating-point value where an unsigned integer index is required, often in array indexing or slice operations.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| rustc 1.70.0 | active | — | — |
| rustc 1.75.0 | active | — | — |
| rustc 1.82.0 | active | — | — |

## Workarounds

1. **Use `as usize` to convert f64 to usize, ensuring the value is non-negative and within range: `let index = value as usize;`** (85% success)
   ```
   Use `as usize` to convert f64 to usize, ensuring the value is non-negative and within range: `let index = value as usize;`
   ```
2. **Use `f64::round()` or `f64::floor()` before casting: `let index = value.round() as usize;`** (80% success)
   ```
   Use `f64::round()` or `f64::floor()` before casting: `let index = value.round() as usize;`
   ```
3. **If the value is from user input or computation, parse or compute it as `usize` directly: `let index: usize = some_usize_source;`** (90% success)
   ```
   If the value is from user input or computation, parse or compute it as `usize` directly: `let index: usize = some_usize_source;`
   ```

## Dead Ends

- **** — Truncation may cause logic errors; the compiler allows it but the behavior is undefined for negative or NaN values. (45% fail)
- **** — Rust requires explicit conversion; this approach is syntactically invalid. (100% fail)
- **** — If the value comes from a computation or input that yields f64, the type mismatch persists. (60% fail)
