Static rustc_lint::unit_bindings::UNIT_BINDINGS
source · pub static UNIT_BINDINGS: &Lint
Expand description
The unit_bindings
lint detects cases where bindings are useless because they have
the unit type ()
as their inferred type. The lint is suppressed if the user explicitly
annotates the let binding with the unit type ()
, or if the let binding uses an underscore
wildcard pattern, i.e. let _ = expr
, or if the binding is produced from macro expansions.
§Example
ⓘ
#![deny(unit_bindings)]
fn foo() {
println!("do work");
}
pub fn main() {
let x = foo(); // useless binding
}
{{produces}}
§Explanation
Creating a local binding with the unit type ()
does not do much and can be a sign of a
user error, such as in this example:
fn main() {
let mut x = [1, 2, 3];
x[0] = 5;
let y = x.sort(); // useless binding as `sort` returns `()` and not the sorted array.
println!("{:?}", y); // prints "()"
}