go build_error ai_generated true

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

ID: go/imported-and-not-used

Also available as: JSON · Markdown · 中文
80%Fix Rate
95%Confidence
0Evidence
2024-01-02First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.x active — — —

Root Cause

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

generic

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 100% fail

    linters respect it but the compiler still errors

  2. 80% fail

    compiles but is dead code and often flagged by vet

  3. 100% fail

    does not disable unused-import errors