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.
Encountered a syntax error.
Self-assignments are redundant and are unlikely to be intentional. This is probably the result of a copy-paste.
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.
.clone()
call on a double reference RS-W1100Calling .clone()
clone on a &&T
copies the inner &T
and not the
underlying T
.
""
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.
Arc::get_mut
RS-S1000In the standard library in Rust before 1.29.0, there is weak synchronization in the
Arc::get_mut
method. This synchronization issue can be lead to memory safety issues
through race conditions.
FIXME
/XXX
/TODO
RS-D1000This block has been marked as FIXME
/XXX
/TODO
. Perhaps you meant to address this?
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!
.