# 错误[E0432]：无法解析导入 `my-crate` -- 在 crate 根中找不到 `my-crate`

- **ID:** `rust/e0432-unresolved-import-crate-name-hyphen`
- **领域:** rust
- **类别:** module_error
- **错误码:** `E0432`
- **验证级别:** ai_generated
- **修复率:** 98%

## 根因

Rust 中带连字符的 crate 名称在代码中会自动转换为下划线；在 use 语句中应使用 `my_crate` 而不是 `my-crate`。

## 版本兼容性

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

## 解决方案

1. ```
   在所有 use 语句中将连字符替换为下划线：`use my_crate::SomeType;`
   ```
2. ```
   在 Cargo.toml 中使用 `package` 键重命名：`my_crate = { package = "my-crate", version = "1.0" }`，然后以 `my_crate` 导入。
   ```
3. ```
   如果需要，使用 `extern crate my_crate as my_crate;` 用于遗留代码。
   ```

## 无效尝试

- **** — extern crate also uses the underscore convention. The hyphen is only valid in Cargo.toml dependency names, not in code. (95% 失败率)
- **** — Cargo.toml dependency names can have hyphens, but the crate name in Rust source is always underscores. Renaming in Cargo.toml is unnecessary. (70% 失败率)
- **** — Hyphens are not valid in Rust identifiers. Use underscores instead. (95% 失败率)
