E1120: result marked must_use is ignored
A value that carries an outcome has to be looked at.
A value that carries an outcome has to be looked at. Two things make a value must-use (ADR-0090):
- a verb marked
meta must_use("reason"), such as one that returns a status code. The message repeats the reason that the declaration gives; - every
Resultand everyOption. AResultcarries an error and anOptionmay hold no value, and the message says so.
A call that is a statement of its own throws its result away, and the compiler
rejects it. A result is used when it is bound to a binding that is used,
returned, passed as an argument, used by an operator or propagated with ?. The tail of an arm of a case or
an if whose value is used is that value, so it is not thrown away.
A binding that holds a Result or an Option and is never mentioned again in
its scope throws the value away in the same way, at the end of the scope, and is
rejected too. Any mention counts as a use (a read, an argument in any role, a
case, a return, ?, drop), anywhere in the scope: the check does not
follow paths.
Example
A Result needs no marker:
A Result held by a binding that nothing uses:
Fix
Bind the result and use it.
Propagate the error with ? when the verb can return it:
Or end the value on purpose with drop, when ignoring it is the intent, as in
a cleanup path:
A binding that nothing uses is replaced by the statement: drop(read_value());
or read_value()?;.
actus check --format json carries these as fixes marked review, and
actus fix lists them without applying them, because each one decides what the
program does with the outcome.
Run actus explain E1120 in your terminal to read this entry offline. Browse Modules & rules or all error codes.