# Go: declared and not used: x / "fmt" imported and not used

**Code:** `declared and not used` · **Category:** Go · **Seen on:** Go

Go refuses to compile code with unused local variables or unused imports.

## Meaning

This keeps code clean, but is annoying while debugging. Use the variable, remove it, or assign to _; for imports, remove them or let goimports manage them automatically.

## Common causes

- Variable assigned but never read
- Leftover import after editing code
- Shadowed variable with := inside a block

## Quick fix

1. Remove the variable/import
2. Assign to the blank identifier _ while debugging
3. Run goimports / gopls on save

## Detailed fix by platform

### Shell

1. 

```go
go install golang.org/x/tools/cmd/goimports@latest
goimports -w .
```


## How to diagnose

1. **Line** — Variable/import named
2. **Shadowing** — := inside if/for blocks?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/go/declared-and-not-used)
