Unused value
WarningUnsafe fixAn expression statement whose value nothing uses: a call, a conversion, an operator or a literal of any type but unit and never. The warning points at the value, and the program still builds. In an if, if let or match whose value is not used, it points at each branch's or arm's value; the body of a function that returns nothing, and the body of a loop, drop their last expression's value too. Write let _ = e to drop a value on purpose; an arm's body is an expression, so there write { let _ = e }. In an if, if let or match, the fix drops every branch's value at once, since a branch with no value beside one with a value is an error; past eight values in one statement it offers no fix, to keep the output small.
Why
A value that nothing reads is usually a mistake: a result that was meant to be stored or printed, or a conversion such as u8(n) that does nothing on its own. Result handling is planned; with it, an unused Result would be an error that nobody handles. Swift warns about every unused result, as Sisu does; Rust warns only for types marked #[must_use].
Broken
fn twice(n: i64) -> i64 {
n * 2
}
fn main() {
twice(21)
}
What sisu says
warning[W0004]: unused value of type `i64` --> W0004.sisu:6:5 | 6 | twice(21) | ^^^^^^^^^ | = help: use it, or write `let _ =` to drop it on purpose help: drop it on purpose | 6 | let _ = twice(21) | +++++++ sisu: 1 warning sisu: for more on a code, run `sisu explain <code>`: W0004
Fixed
fn twice(n: i64) -> i64 {
n * 2
}
fn main() {
print(twice(21))
}
Sisu