← All lints

unread_field

L0202Stylewarn

Struct field never read

a struct field that is never read

Flagged
struct Pt:
    x: Int
    y: Int
let p = Pt(x: 1, y: 2)
print(p.x)
Write instead
struct Pt:
    x: Int
let p = Pt(x: 1)
print(p.x)

Why

A field declared on a struct is never read anywhere in the file. Remove unused fields to keep structs compact and clear.

The practice it serves

Spelling that hides what the code means. Family: R. Redundancy and dead code.

Not flagged

A near miss: close to the pattern, but not it.

Near miss
struct Pt:
    x: Int
    y: Int
let p = Pt(x: 1, y: 2)
print(p.x + p.y)

Turn it off

For one block, wrap it in with lint(unread_field: allow):. For a project, add unread_field = "allow" under [lints] in cp.toml.

Generated from spec/lints/unread_field, the same record the linter is built from.