# 错误[E0308]：类型不匹配：期望 `usize`，发现 `u32`

- **ID:** `rust/e0308-expected-usize-found-u32`
- **领域:** rust
- **类别:** type_error
- **错误码:** `E0308`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

在需要 usize 的地方（如数组索引或切片操作）使用了固定大小整数（如 u32）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.65 | active | — | — |
| 1.70 | active | — | — |
| 1.75 | active | — | — |

## 解决方案

1. ```
   Convert explicitly with `try_into()`: `let idx: usize = index.try_into().unwrap();`
   ```
2. ```
   Use `as` conversion if the value is guaranteed to fit: `let idx = index as usize;`
   ```
3. ```
   Change the function signature to accept usize: `fn process(index: usize)`
   ```

## 无效尝试

- **Casting with `as`: `index as usize` without checking for overflow on 32-bit platforms** — This works syntactically but may cause silent truncation on 32-bit systems if the u32 value exceeds 2^32. (60% 失败率)
- **Changing the variable type to usize everywhere** — May break other code that expects u32, and does not address the root cause of type mismatch. (70% 失败率)
