A function with high cyclomatic complexity can be hard to understand and maintain. Cyclomatic complexity is a software metric that measures the number of independent paths through a function. A higher cyclomatic complexity indicates that the function has more decision points and is more complex.
Function arguments having similar names that differ by an underscore affect code readability.
u8
RS-W1080Casting values from a larger type to a smaller type is error-prone. This can be
avoided when casting char
literals to u8
by using the byte literal
directly.
""
or []
when .is_empty()
could be used RS-W1102The intent expressed by .is_empty()
is a lot clearer than comparison to ""
or []
. Prefer .is_empty()
where applicable.
Successive wildcard patterns (_
) add noise to code, use the rest pattern (..
) instead.
.filter(..).next()
RS-W1023.filter(..).next()
is equivalent to .find(..)
. Prefer .find(..)
for
readability.
Arguments in method calls need not be parenthesized. The level of nesting in code is more obvious when unnecessary parentheses are omitted.
use
statement RS-C1002An import list with just one item can be simplified. The unnecessary braces can be safely omitted.
Patterns of the form name @ _
are redundant. It is always more readable to use a direct binding.
Expressions of the form x == true
, !y == false
are unnecessary. Consider using the variable directly.
Assertions on true
are optimized out by the compiler and can be removed
safely. Asserting false
will always result in a panic, prefer using
panic!()
or unreachable!()
with a meaningful message.
Extra parentheses increase expression nesting without adding meaning. They make code harder to read.
Enumeration variants with the same prefix or suffix as the enumeration name are repetitive. Variants should describe themselves, and not include the name of the parent enum in their names.
In tuple or struct patterns, zero or more "remaining" elements can be discarded
using the rest (..
) pattern and exactly one element can be discarded using
the wildcard pattern (_
). This checker looks for wildcard patterns next to a
rest pattern. The wildcard is unnecessary because the rest pattern can match
that element as well.
print!
macro with newline RS-C1005Several macros in the standard library such as print!
and eprint!
have
analogous macros such as println!
and eprintln!
that append a newline. Instead of
calling print!
with an explicit newline character at the end of the format string,
prefer its alternative, println!
.
Empty format strings in macros such as println!
and eprintln!
have no effect. Simply use println!()
instead of println!("")
,
which is much simpler.
Hexadecimal literals with mixed-case letter digits look confusing.
if
condition RS-C1008Using block expressions as if
conditions can confuse readers of this code.
This checker looks for struct field patterns bound to wildcards. Prefer ..
instead, as it is shorter and directs focus towards fields that are actually bound.
Matching over a boolean expression is less readable than using an if-else
block.