Returning the unit type from a closure expecting an Ord
type is likely a mistake caused by an extra semi-colon. This is because the
unit type implements Ord
but doesn’t serve the intended sorting purpose, making the code misleading and potentially incorrect.
Code examples
Noncompliant code example
let mut twins = vec![(1, 1), (2, 2)];
twins.sort_by_key(|x| { x.1; }); // Noncompliant: Closure returns unit type due to unnecessary semi-colon.
Compliant solution
let mut twins = vec![(1, 1), (2, 2)];
twins.sort_by_key(|x| x.1); // Compliant: Closure correctly returns an `Ord` type.