Rust

Rust

Made by DeepSource
Found occurrence of .filter(..).next() RS-W1023
Anti-pattern
Minor

.filter(..).next() is equivalent to .find(..). Prefer .find(..) for readability.

Found use of .clone() in assignment RS-W1070
Anti-pattern
Minor

Consider using .clone_from() instead of assigning the result of .clone().

clone_from() may perform better in some cases because some structs may have custom implementations of clone_from(), which improve performance by avoiding needless allocations.

Found redundant use of mem::replace RS-W1113
Anti-pattern
Major

The std::mem module provides the take() method to acquire the current value and replace it with the default value of the same type. Prefer using this over mem::replace with T::default().

Consider using .clamp(min, max), instead of .max(min).min(max) or .min(max).max(min) RS-W1069
Anti-pattern
Minor

Chained Ord::min and Ord::max functions can be replaced with Ord::clamp, which is also a more readable solution.

Found comparison with None RS-W1108
Anti-pattern
Minor
Autofix

Checking if a value is None via a direct comparison is usually inspired from other programming languages (e.g. foo is None in Python). In Rust, the Eq trait is used to perform the comparison, which is unneeded. The Option type provides the is_none() and is_some() methods which return a boolean, allowing for more idoimatic comparison.

Function with cyclomatic complexity higher than threshold RS-R1000
Anti-pattern
Minor

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.

Found redundant use of mem::replace RS-W1112
Anti-pattern
Major

Option provides the take() method for acquiring its current value (Some(..) or None) and replacing it with None. Prefer using this over mem::replace with None.

Found manual implementation of std::ptr::null() RS-W1078
Anti-pattern
Minor
Autofix

Casting 0 as *const is the same as std::ptr::null(), which is more idiomatic and readable. Similarly 0 as *mut is same as std::ptr::null_mut().

Found usage of then_some(..).unwrap_or(..) RS-C1015
Anti-pattern
Minor
Autofix

Using then_some(..).unwrap_or(..) obfuscates the comparison itself and reduces code readability. It can be better written as an if-else block.

Unnecessary OnceCell wrapper around Mutex RS-W1135
Anti-pattern
Minor

When using static Mutex in Rust, it was common practice to wrap them inside a OnceCell for safe initialization. Since Rust 1.63, this is no longer necessary as global static Mutex's can be initialized without any wrapper. Therefore, using a OnceCell with a Mutex is redundant and adds unnecessary complexity to the code.

If your code uses a OnceCell to wrap a global static Mutex, you can simplify it by removing the OnceCell wrapper and initializing the Mutex directly.

Found useless lint attribute RS-W1074
Anti-pattern
Minor
Autofix

Lint attributes have no effect on crate imports. Neither can lint-attributes affect module-space attributes of the imported items.

Found unnecessary boolean comparison RS-W1001
Anti-pattern
Minor
Autofix

Expressions of the form x == true, !y == false are unnecessary. Consider using the variable directly.

Found manual implementation of Seek::rewind RS-W1046
Anti-pattern
Minor
Autofix

Calling Seek::seek with SeekFrom::Start(0) as the position is equivalent to Seek::rewind. Consider using Seek::rewind to improve readibility.

Found occurrence of Rc::new("..") RS-W1062
Anti-pattern
Minor
Autofix

Prefer Rc::from("..") over Rc::new("..").Rc<&str>` is a pointer to a pointer. This adds another level of indirection without any benefit whatsoever.

Found error-prone cast to u8 RS-W1080
Anti-pattern
Minor
Autofix

Casting 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.

Found empty tuple struct or tuple variant RS-W1125
Anti-pattern
Minor

Empty tuple fields in structs or enum variants do not affect the program in a meaningful way other than making the variant or struct identifier a constructor type rather than a value type. Consider revisiting this definition.

Found manual implementation of T::BITS RS-W1132
Anti-pattern
Minor

All integer types provide the size of the type in bits through T::BITS. Consider using this instead of manually calling std::mem::size_of::<T>() and multiplying the result by 8.

Found manual implementation of vec.first() RS-W1116
Anti-pattern
Minor

The Vec type provides the first() and first_mut() methods to retrieve the first element of the vector. Similarly, the VecDeque type provides the front() and front_mut() methods.

Prefer using these instead of get(0) and get_mut(0).

Found print! in implementation of Debug RS-W1133
Anti-pattern
Minor

The fmt method provided by the Debug trait uses a formatter to generate the output string. It does not directly write to stdout or stderr. Using print! or eprint! in this implementation leads to incorrect functionality. Instead, use the standard suite of debug representations provided by the Formatter trait (debug_struct, debug_tuple, debug_list, debug_set, debug_map). If you wish to use a custom representation for debugging, you can use the write! macro.