Closed
Description
I recently wrote a test like this
assert_eq!(&my_complicated_function().sort(), &[4, 3, 7, 1].sort()) // works!
but much to my surprise, the test kept passing even if I changed the literal
assert_eq!(&my_complicated_function().sort(), &[4, 3].sort()) // works!
at this point I realized that what I wrote was as good as this useless comparison
assert_eq!((), ())
In order to catch people who try to do things like this, I suggest that we lint comparing two expressions of unit type, since the result will always be true and it would be more straightforward just to write two lines for each expression e.g.
my_complicated_function();
[4, 3, 7, 1];
In addition to the canonical Unit Type ()
, I suggest that we lint for expressions of any user-created unit type such as:
struct UnitStruct;
enum UnitEnum {
OnlyVariant,
}
// and maybe
enum TechnichallyUnitStruct {
unit_field: (),
}
enum TechnichallyUnitEnum {
UnitVariant(UnitStruct, ()),
NeverVariant(!),
}
// etc...
Thoughts?