# 错误[E0080]：常量求值错误：除以零

- **ID:** `rust/e0080-constant-evaluation-error-divide-by-zero`
- **领域:** rust
- **类别:** const-eval
- **错误码:** `E0080`
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

常量表达式在编译时执行了除以零或取模零的操作。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.63.0 | active | — | — |
| 1.66.0 | active | — | — |
| 1.70.0 | active | — | — |

## 解决方案

1. ```
   通过条件确保除数非零：`const DIV: u32 = if DENOM != 0 { NUM / DENOM } else { 0 };`
   ```
2. ```
   使用检查算术：`const RESULT: Option<u32> = NUM.checked_div(DENOM);`
   ```

## 无效尝试

- **Using `unsafe` to bypass the check in const context** — `unsafe` is not allowed in const contexts; compiler rejects it. (100% 失败率)
- **Changing the divisor to a variable to defer evaluation to runtime** — If the divisor is still zero at runtime, it causes a panic; compile-time check is bypassed but runtime error remains. (70% 失败率)
