Rust

Rust

By DeepSource

Found occurrence of .filter(..).next() RS-W1023
Anti-pattern

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

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

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

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

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

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

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
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
Autofix

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

Found useless lint attribute RS-W1074
Anti-pattern
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
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
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
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
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

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

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

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

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.

Found redundant transmute between the type T and T RS-W1117
Anti-pattern

Transmutes to the original type of the object is redundant. Such code creates the illusion of complexity and reduces readability.

Found usage of FileType::is_file RS-A1000
Anti-pattern

If the intention is to read bytes from a file, consider using !FileType::is_dir instead of FileType::is_file, or ensure that the file is a symlink. FileType::is_file itself is mutually exclusive to is_symlink() and hence not all readable files will return is_file() true.

Using !FileType::is_dir is a simpler way of checking if a given file can be read from or written to.