Skip to content
unused-function · Lint · warning

Unused function

A top-level function is never called and is not marked `pub`, `@test`, `@bench`, `@export`, an HTTP route, or `main`.

Why this fires

A top-level function declaration is never called from anywhere in the file, and it is not flagged with an attribute that exempts it from the unused check.

fn helper(x: int) -> int {   // warning: unused-function `helper`
    return x * 2
}

fn main() {
    print("nothing calls helper")
}

Exemptions

The lint deliberately skips functions that have an obvious external caller:

Marker Why it is exempt
pub fn ... Visible to consumers of the module
fn main() Program entry point
@test, @bench Discovered by the test/bench harness
@export Exposed to the host (e.g. WASM)
@get, @post, @put, ... HTTP route handlers
@route, @middleware, @handler, @endpoint HTTP framework hooks
@on, @event Lifecycle / event hooks

If your function should be reachable through one of these, add the right decorator.

Fix it

1. Delete the function

The simple case — code rot.

2. Call it

If something should call it, add the call site or fix the typo at the existing one.

3. Make it pub

If the function is part of a module's public API, mark it pub. The lint stops firing and the function becomes visible to imports.

pub fn helper(x: int) -> int {
    return x * 2
}

4. @allow("unused-function")

For the rare case where a function is genuinely there as a placeholder (e.g. WIP, planned wire-up):

@allow("unused-function")
fn future_thing() {
    // TODO(2026-Q3): wire from new pipeline
}

Use sparingly — placeholder functions tend to rot.

enespt-br