go build_error ai_generated true

./main.go:5:2: 导入了但未使用:"fmt"

./main.go:5:2: imported and not used: "fmt"

ID: go/imported-and-not-used

其他格式: JSON · Markdown 中文 · English
80%修复率
95%置信度
0证据数
2024-01-02首次发现

版本兼容性

版本状态引入弃用备注
1.x active — — —

根因分析

声明了导入,但文件中未引用该包的任何标识符。Go 将未使用的导入视为编译错误。

English

An import is declared but no identifier from that package is referenced in the file. Go treats unused imports as a compile error.

generic

解决方案

  1. 98% 成功率
    // delete the import line, or run:
    goimports -w ./...
    # or: gofmt -w main.go
  2. 90% 成功率
    import _ "net/http/pprof"

无效尝试

常见但无效的做法:

  1. 100% 失败

    linters respect it but the compiler still errors

  2. 80% 失败

    compiles but is dead code and often flagged by vet

  3. 100% 失败

    does not disable unused-import errors