Static rustc_lint::unused::UNUSED_RESULTS
source · pub static UNUSED_RESULTS: &Lint
Expand description
The unused_results
lint checks for the unused result of an
expression in a statement.
Example
#![deny(unused_results)]
fn foo<T>() -> T { panic!() }
fn main() {
foo::<usize>();
}
{{produces}}
Explanation
Ignoring the return value of a function may indicate a mistake. In
cases were it is almost certain that the result should be used, it is
recommended to annotate the function with the must_use
attribute.
Failure to use such a return value will trigger the unused_must_use
lint which is warn-by-default. The unused_results
lint is
essentially the same, but triggers for all return values.
This lint is “allow” by default because it can be noisy, and may not be
an actual problem. For example, calling the remove
method of a Vec
or HashMap
returns the previous value, which you may not care about.
Using this lint would require explicitly ignoring or discarding such
values.