Skip to content

Implement zlint rule 'unused-decls' #16

@rockorager

Description

@rockorager

Rule: unused-decls

Disallows container-scoped variables that are declared but never used, including top-level declarations.

The Zig compiler checks for unused locals within functions, but does not flag unused container-scoped const/var declarations or unused functions. This rule fills that gap.

Example

// Bad: declared but never referenced
const UNUSED_CONSTANT: u32 = 42;

pub fn main() void {
    // ...
}

Implementation notes

Complexity: requires reference tracking across the module

This needs to track all container-scoped declarations and all identifier references, then report declarations with zero references. ziglint already does this for imports (Z013 tracks used_identifiers and import_bindings), so extending to all container decls is conceptually similar but broader.

Note that even zlint's implementation is incomplete — their docs note it doesn't handle member access expressions (foo.bar) or method calls correctly yet, and only checks top-level const declarations.

Reference

Suggested-By: @mattrobenolt

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedAccepted for implementationrule-requestRequest for a new lint rule

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions