Why this fires
A let-bound name (or a function parameter) is never read after it is introduced. Either the binding is leftover from an earlier version of the code, or it shadows a name the rest of the body actually wanted to use.
fn greet(name: str) {
let greeting = "Hello" // warning: unused-variable `greeting`
print("Hi, ${name}")
}
Fix it
There are three sensible responses, depending on the intent:
1. Delete the binding
If the value is not needed, remove it:
fn greet(name: str) {
print("Hi, ${name}")
}
2. Use it
If the variable was supposed to be used and the lint surfaced a typo or a forgotten reference, fix the reference:
fn greet(name: str) {
let greeting = "Hello"
print("${greeting}, ${name}")
}
3. Mark it intentionally unused with _
Parameters required by an interface or trait — and let bindings whose side effects matter even if the value does not — should be prefixed with _. The lint treats _-prefixed names as deliberately unused:
fn on_event(_event: Event, ctx: Context) {
ctx.tick()
}
For a discarded RHS, the bare _ pattern also works:
let _ = compute_and_log()
Why _ instead of suppressing the rule
_-prefix is a permanent code-level signal that the next reader sees, while @diagnostic(off, "unused-variable") hides the lint and (more importantly) hides the next time you accidentally orphan a binding. Prefer _.