go compilation ai_generated true

declared and not used

ID: go/declared-not-used

Also available as: JSON · Markdown
99%Fix Rate
99%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
121 active
1 active

Root Cause

Go does not allow unused variables — a variable was declared but never read.

generic

Workarounds

  1. 97% success Remove the unused variable declaration
    If you don't need it, delete it
  2. 95% success Use _ for intentionally discarded values: _, err := fn()
    The blank identifier _ explicitly discards a value

    Sources: https://go.dev/doc/effective_go#blank

Dead Ends

Common approaches that don't work:

  1. Assigning to a throwaway: _ = unused 55% fail

    Suppresses the error but why declare it?

  2. Moving the declaration to a different scope 80% fail

    Doesn't fix it; still unused in the new scope

Error Chain

Leads to: