Encountered a syntax error.
Self-assignments are redundant and are unlikely to be intentional. This is probably the result of a copy-paste.
.clone()
call on a double reference RS-W1100Calling .clone()
clone on a &&T
copies the inner &T
and not the
underlying T
.
Encountered invalid regex syntax in Regex::new
or RegexBuilder::new
. Refer
to the occurrence message for more details.
The remainder of a division by 1 is always 0. On the other hand, the remainder of a division by -1 is may cause panics/overflows if the dividend is the lower bound of its integral type.
if-else
expressions with the same if
and else
parts are probably a result
of a copy-paste. The result of the expression is independent of the condition.
Consecutive if
statements with the same condition are probably the result of a
copy-paste. This checker ignores function calls as they could have side-effects.
env
functions RS-W1015Calls to the std::env
functions that use string literals instead of a
static strings can lead to bugs due to spelling errors.
unwrap
on option_env!
macro RS-W1016Unwrapping the result of the option_env!
macro will panic at runtime if the
environment variable does not exist. The env!
macro catches this at compile
time.
Generic type parameters or pattern captures that have the same name as certain builtin-types can cause unexpected errors.
fs::create_dir
RS-W1032fs::create_dir_all
is preferable over fs::create_dir
as it creates all
missing components in the provided path without erroring out.
chars
RS-W1095Extending one String with another is possible through .extend(s.chars())
. However, this is better expressed using push_str(s)
.
NaN
RS-E1012Comparing a floating point with NaN
using ==
or !=
is redundant. NaN
cannot be compared to anything, not even itself. Use .is_nan()
instead.
mem::forget
or mem::drop
on a reference RS-E1010Calling std::mem::forget
(or std::mem::drop
) on a reference will forget (or
drop) the reference itself, which effectively does nothing. The underlying
reference value will remain unaffected.
mem::forget
or mem::drop
on a Copy type RS-E1011For types that implement the Copy
trait, std::mem::forget
(or
std::mem::drop
) effectively does nothing because the type is copied into the
function call, and the newly copied type is forgotten (or dropped).
Additionally, Copy
types do not have destructors; there is nothing for
std::mem::forget
or (or std::mem::drop
) to do.
The unit value is always equal to itself. Comparisons against the unit value are probably the result of accidental semicolons.
Letter ranges can be constructed by using the inclusive or exclusive range
operators. However, ranges from 'a'
to 'z
' (or '1'
to '9'
) constructed
with the exclusive range operator exclude the upper bound: 'z'
(or '9'
),
because such ranges are half open.
Several mathematical values such as π (pi) or τ (tau) have highly accurate constants defined in the standard library. Consider using these values directly to reduce manual error.
.step_by(0)
RS-E1003Calling .step_by(0)
on an iterator panics. Consider using panic!
if this is intentional.
Option
type RS-E1004Calling .next()
on an iterator produces an Option<T>
, which also implements
IntoIterator
. This is probably a mistake, consider revisiting this for
loop.