Sisu
W0012

Function, method, class, enum or constant that no live code uses

Warning

Built from the repository at commit a8614dc.

A function, method, class, enum or constant that no live code uses is a warning, and the program still builds. Live code is main, each function, method and constant whose name starts with _, and all the code that live code calls or names. A function or a method is used when live code calls it. A class or an enum is used when live code builds it, or one of its variants. A type that names a class does not use it. A constant is used when live code or a live constant names it. A use in dead code does not count, and the warning shows up to three such uses. A method of a class or an enum that nothing builds gets no warning of its own: its class or enum gets the warning. A name that starts with _ gets no warning. The warning does not show while the program has an error, because a use in code that fails to check can be missed. There is no fix, because only you know if the code is still necessary.

Why

Dead code is often what a refactor leaves behind. It costs time to read and to keep up to date, and it can make a reader think that a path still runs. Only a use in live code counts. When old_report is the only function that calls format_row, and nothing calls old_report, both are dead. Each one gets its own warning, and the warning for format_row shows the call in old_report. Delete both, or name old_report _old_report to keep it on purpose: then format_row is live too.

Broken

fn old_report() {
    print("report")
}

fn main() {
    print("done")
}

What sisu says

warning[W0012]: function `old_report` is never called
 --> W0012.sisu:1:4
  |
1 | fn old_report() {
  |    ^^^^^^^^^^ never called
  |
  = help: delete it, or name it `_old_report` if it is kept on purpose

sisu: 1 warning
sisu: for more on a code, run `sisu explain <code>`: W0012

Fixed

fn main() {
    print("done")
}

Related

  • W0004: unused value.
  • W0013: field that no live code reads, or variant that no live code builds.