# 错误[E0308]：`match` 分支的类型不兼容

注意：期望 `Result<(), MyError>`
      发现 `Result<(), OtherError>`

- **ID:** `rust/e0308-match-arm-different-types-with-generic`
- **领域:** rust
- **类别:** type_error
- **错误码:** `E0308`
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

不同的 match 分支返回具有不同错误类型的 `Result` 类型，即使两者都实现了 `From` 或 `Into`。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| rustc 1.74 | active | — | — |
| rustc 1.75 | active | — | — |

## 解决方案

1. ```
   在每个分支上使用 `.map_err()` 将错误转换为公共类型：`arm1.map_err(|e| MyError::from(e))`。
   ```
2. ```
   定义一个统一的错误枚举，包装两种错误类型，并为每种类型实现 `From`。
   ```

## 无效尝试

- **** — Only fixes one arm; compiler still sees mismatch if the other arm has a different error type. (70% 失败率)
- **** — Panics on error; not a proper fix for error handling. (85% 失败率)
