Option already has the method replace() for taking its current value (Some(…) or None) and replacing it with Some(…). Clippy puts this lint in the style group, at the level warn.
- Code
mem_replace_option_with_some- Severity
- warn
- Since
- 1.87.0
std::mem module already has the method take to take the current value and replace it with the default value of that type. Clippy puts this lint in the style group, at the level warn.
- Code
mem_replace_with_default- Severity
- warn
- Since
- 1.42.0
This will lead to undefined behavior even if the value is overwritten later, because the uninitialized value may be observed in the case of a panic. Clippy puts this lint in the correctness group, at the level deny.
- Code
mem_replace_with_uninit- Severity
- deny
- Since
- 1.39.0
To improve readability by requiring that every variable has a name more specific than a single letter can be. Clippy puts this lint in the restriction group, at the level allow.
- Code
min_ident_chars- Severity
- allow
- Since
- 1.72.0
This is in all probability not the intended outcome. At the least it hurts readability of the code. Clippy puts this lint in the correctness group, at the level deny.
- Code
min_max- Severity
- deny
Nothing. misaligned_transmute
This lint has been deprecated Clippy puts this lint in the deprecated group, at the level none.
- Code
misaligned_transmute- Severity
- none
Substracting leading_zeros from the number of bits of another type might be a buggy implementation of the bit_width method. Clippy puts this lint in the suspicious group, at the level warn.
- Code
mismatched_bit_width_type- Severity
- warn
- Since
- 1.98.0
Specifically, a parameter in an impl block which has the same name as a parameter in the type def, but is in a different place. Type parameters are determined by their position rather than name. Naming type parameters inconsistently may cause you to refer to the wrong type parameter. Clippy puts this lint in the pedantic group, at the level allow.
- Code
mismatching_type_param_order- Severity
- allow
- Since
- 1.63.0
It is most likely that such a method is a bug caused by a typo or by copy-pasting. Clippy puts this lint in the suspicious group, at the level warn.
- Code
misnamed_getters- Severity
- warn
- Since
- 1.67.0
Most likely these are bugs where one meant to write a op= b. Clippy puts this lint in the suspicious group, at the level warn.
- Code
misrefactored_assign_op- Severity
- warn
Without a good custom message, it’d be hard to understand what went wrong when the assertion fails. A good custom message should be more about why the failure of the assertion is problematic and not what is failed because the assertion already conveys that. Clippy puts this lint in the restriction group, at the level allow.
- Code
missing_assert_message- Severity
- allow
- Since
- 1.70.0
In the general case where the compiler does not have a lot of information about the length of a slice, indexing it repeatedly will generate a bounds check for every single index. Clippy puts this lint in the restriction group, at the level allow.
- Code
missing_asserts_for_indexing- Severity
- allow
- Since
- 1.74.0
Not having the function const prevents callers of the function from being const as well. Clippy puts this lint in the nursery group, at the level allow.
- Code
missing_const_for_fn- Severity
- allow
- Since
- 1.34.0
The thread_local! macro wraps static declarations and makes them thread-local. It supports using a const keyword that may be used for declarations that can be evaluated as a constant expression. This can enable a more efficient thread local implementation that can avoid lazy initialization. For types that do not need to be dropped, this can enable an even more efficient implementation that does not need to track any additional state. Clippy puts this lint in the perf group, at the level warn.
- Code
missing_const_for_thread_local- Severity
- warn
- Since
- 1.77.0
Doc is good. rustc has a MISSING_DOCS allowed-by-default lint for public members, but has no way to enforce documentation of private items. This lint fixes that. Clippy puts this lint in the restriction group, at the level allow.
- Code
missing_docs_in_private_items- Severity
- allow
Consistency is important; if a project has defined import renames, then they should be followed. More practically, some item names are too vague outside of their defining scope, in which case this can enforce a more meaningful naming. Clippy puts this lint in the style group, at the level warn.
- Code
missing_enforced_import_renames- Severity
- warn
- Since
- 1.55.0
Documenting the type of errors that can be returned from a function can help callers write code to handle the errors appropriately. Clippy puts this lint in the pedantic group, at the level allow.
- Code
missing_errors_doc- Severity
- allow
- Since
- 1.41.0
A common mistake is to forget to update manual Debug implementations when adding a new field to a struct or a new variant to an enum. Clippy puts this lint in the pedantic group, at the level allow.
- Code
missing_fields_in_debug- Severity
- allow
- Since
- 1.70.0
When a function is not marked #[inline], it is not a “small” candidate for automatic inlining, and LTO is not in use, then it is not possible for the function to be inlined into the code of any crate other than the one in which it is defined. Depending on the role of the function and the relationship of the crates, this could significantly reduce performance. Clippy puts this lint in the restriction group, at the level allow.
- Code
missing_inline_in_public_items- Severity
- allow
Documenting the scenarios in which panicking occurs can help callers who do not want to panic to avoid those situations. Clippy puts this lint in the pedantic group, at the level allow.
- Code
missing_panics_doc- Severity
- allow
- Since
- 1.51.0
Unsafe functions should document their safety preconditions, so that users can be sure they are using them safely. Clippy puts this lint in the style group, at the level warn.
- Code
missing_safety_doc- Severity
- warn
- Since
- 1.39.0
The loop body should have something like thread::park() or at least std::hint::spin_loop() to avoid needlessly burning cycles and conserve energy. Perhaps even better use an actual lock, if possible. Clippy puts this lint in the perf group, at the level warn.
- Code
missing_spin_loop- Severity
- warn
- Since
- 1.61.0
To ensure that a certain implementation implements every method; for example, a wrapper type where every method should delegate to the corresponding method of the inner type’s implementation. Clippy puts this lint in the restriction group, at the level allow.
- Code
missing_trait_methods- Severity
- allow
- Since
- 1.66.0
If not, one or more unexpected types could be used during transmute(), potentially leading to Undefined Behavior or other problems. Clippy puts this lint in the suspicious group, at the level warn.
- Code
missing_transmute_annotations- Severity
- warn
- Since
- 1.79.0
This is most probably a typo Clippy puts this lint in the correctness group, at the level deny.
- Code
mistyped_literal_suffixes- Severity
- deny
- Since
- 1.30.0
Having both style of said attributes makes it more complicated to read code. Clippy puts this lint in the style group, at the level warn.
- Code
mixed_attributes_style- Severity
- warn
- Since
- 1.78.0
It looks confusing. Clippy puts this lint in the style group, at the level warn.
- Code
mixed_case_hex_literals- Severity
- warn
While [the evaluation order of sub-expressions] is fully specified in Rust, it still may be confusing to read an expression where the evaluation order affects its behavior. Clippy puts this lint in the restriction group, at the level allow.
- Code
mixed_read_write_in_expression- Severity
- allow
Having multiple module layout styles in a project can be confusing. Clippy puts this lint in the restriction group, at the level allow.
- Code
mod_module_files- Severity
- allow
- Since
- 1.57.0
A typical beginner mistake is to have mod foo; and again mod foo { .. } in foo.rs. The expectation is that items inside the inner mod foo { .. } are then available through foo::x, but they are only available through foo::foo::x. If this is done on purpose, it would be better to choose a more representative module name. Clippy puts this lint in the style group, at the level warn.
- Code
module_inception- Severity
- warn
It requires the user to type the module name twice in each usage, especially if they choose to import the module rather than its contents. Clippy puts this lint in the restriction group, at the level allow.
- Code
module_name_repetitions- Severity
- allow
- Since
- 1.33.0
The results of modulo (%) operation might differ depending on the language, when negative numbers are involved. If you interop with different languages it might be beneficial to double check all places that use modulo arithmetic. Clippy puts this lint in the restriction group, at the level allow.
- Code
modulo_arithmetic- Severity
- allow
- Since
- 1.42.0
The result for a divisor of one can only ever be zero; for minus one it can cause panic/overflow (if the left operand is the minimal value of the respective integer type) or results in zero. No one will write such code deliberately, unless trying to win an Underhanded Rust Contest. Even for that contest, it’s probably a bad idea. Use something more underhanded. Clippy puts this lint in the correctness group, at the level deny.
- Code
modulo_one- Severity
- deny
While this is in most cases already a type mismatch, the result of an assignment being () can throw off people coming from languages like python or C, where such assignments return a copy of the assigned value. Clippy puts this lint in the suspicious group, at the level warn.
- Code
multi_assignments- Severity
- warn
- Since
- 1.65.0
It can be confusing for developers when seeing bounds for a generic in multiple places. Clippy puts this lint in the style group, at the level warn.
- Code
multiple_bound_locations- Severity
- warn
- Since
- 1.78.0
This bloats the size of targets, and can lead to confusing error messages when structs or traits are used interchangeably between different versions of a crate. Clippy puts this lint in the cargo group, at the level allow.
- Code
multiple_crate_versions- Severity
- allow
Splitting the implementation of a type makes the code harder to navigate. Clippy puts this lint in the restriction group, at the level allow.
- Code
multiple_inherent_impl- Severity
- allow
Combined with undocumented_unsafe_blocks, this lint ensures that each unsafe operation must be independently justified. Combined with unused_unsafe, this lint also ensures elimination of unnecessary unsafe blocks through refactoring. Clippy puts this lint in the restriction group, at the level allow.
- Code
multiple_unsafe_ops_per_block- Severity
- allow
- Since
- 1.69.0
Not bad at all, this lint just shows places where you could add the attribute. Clippy puts this lint in the pedantic group, at the level allow.
- Code
must_use_candidate- Severity
- allow
- Since
- 1.40.0
Unit values are useless. The attribute is likely a remnant of a refactoring that removed the return type. Clippy puts this lint in the style group, at the level warn.
- Code
must_use_unit- Severity
- warn
- Since
- 1.40.0
This will not trigger if no unsafe code exists as there are multiple safe functions which will do this transformation Creating a mutable reference which can be repeatably derived from an immutable reference is unsound as it allows creating multiple live mutable references to the same object. Clippy puts this lint in the correctness group, at the level deny.
- Code
mut_from_ref- Severity
- deny
This is usually just a typo or a misunderstanding of how references work. Clippy puts this lint in the pedantic group, at the level allow.
- Code
mut_mut- Severity
- allow
Mutex::lock is less efficient than calling Mutex::get_mut. In addition you also have a statically guarantee that the mutex isn’t locked, instead of just a runtime guarantee. Clippy puts this lint in the style group, at the level warn.
- Code
mut_mutex_lock- Severity
- warn
- Since
- 1.49.0
One might think that modifying the mutable variable changes the loop bounds. It doesn’t. Clippy puts this lint in the suspicious group, at the level warn.
- Code
mut_range_bound- Severity
- warn
All of HashMap, HashSet, BTreeMap and BtreeSet rely on either the hash or the order of keys be unchanging, so having types with interior mutability is a bad idea. Clippy puts this lint in the suspicious group, at the level warn.
- Code
mutable_key_type- Severity
- warn
- Since
- 1.42.0
Using a mutex just to make access to a plain bool or reference sequential is shooting flies with cannons. std::sync::atomic::AtomicBool and std::sync::atomic::AtomicPtr are leaner and faster. Clippy puts this lint in the restriction group, at the level allow.
- Code
mutex_atomic- Severity
- allow
Using a mutex just to make access to a plain integer sequential is shooting flies with cannons. std::sync::atomic::AtomicUsize is leaner and faster. Clippy puts this lint in the restriction group, at the level allow.
- Code
mutex_integer- Severity
- allow
The bytecount crate has methods to count your bytes faster, especially for large slices. Clippy puts this lint in the pedantic group, at the level allow.
- Code
naive_bytecount- Severity
- allow
Increases the amount and decreases the readability of code Clippy puts this lint in the complexity group, at the level warn.
- Code
needless_arbitrary_self_type- Severity
- warn
- Since
- 1.47.0
The len() and is_empty() methods are also directly available on strings, and they return identical results. In particular, len() on a string returns the number of bytes. Clippy puts this lint in the complexity group, at the level warn.
- Code
needless_as_bytes- Severity
- warn
- Since
- 1.84.0
The bitwise operators do not support short-circuiting, so it may hinder code performance. Additionally, boolean logic “masked” as bitwise logic is not caught by lints like unnecessary_fold Clippy puts this lint in the pedantic group, at the level allow.
- Code
needless_bitwise_bool- Severity
- allow
- Since
- 1.54.0
Redundant code. Clippy puts this lint in the complexity group, at the level warn.
- Code
needless_bool- Severity
- warn
Redundant code. Clippy puts this lint in the complexity group, at the level warn.
- Code
needless_bool_assign- Severity
- warn
- Since
- 1.71.0
Suggests that the receiver of the expression borrows the expression. Clippy puts this lint in the style group, at the level warn.
- Code
needless_borrow- Severity
- warn
This pattern has no effect in almost all cases. Clippy puts this lint in the complexity group, at the level warn.
- Code
needless_borrowed_reference- Severity
- warn
Suggests that the receiver of the expression borrows the expression. Clippy puts this lint in the style group, at the level warn.
- Code
needless_borrows_for_generic_args- Severity
- warn
- Since
- 1.74.0
The str type already implements the is_ascii method. Clippy puts this lint in the suspicious group, at the level warn.
- Code
needless_character_iteration- Severity
- warn
- Since
- 1.81.0
collect causes the allocation of a new data structure, when this allocation may not be needed. Clippy puts this lint in the nursery group, at the level allow.
- Code
needless_collect- Severity
- allow
- Since
- 1.30.0
The lint also checks if the last statement in the loop is a continue Having explicit else blocks for if statements containing continue in their THEN branch adds unnecessary branching and nesting to the code. Having an else block containing just continue can also be better written by grouping the statements following the whole if statement within the THEN block and omitting the else block completely. Clippy puts this lint in the pedantic group, at the level allow.
- Code
needless_continue- Severity
- allow
The test can be shorter (and likely more readable) if the fn main() is left implicit. Clippy puts this lint in the style group, at the level warn.
- Code
needless_doctest_main- Severity
- warn
- Since
- 1.40.0
An empty else branch does nothing and can be removed. Clippy puts this lint in the style group, at the level warn.
- Code
needless_else- Severity
- warn
- Since
- 1.72.0
for_each may be used after applying iterator transformers like filter for better readability and performance. It may also be used to fit a simple operation on one line. But when none of these apply, a simple for loop is more idiomatic. Clippy puts this lint in the pedantic group, at the level allow.
- Code
needless_for_each- Severity
- allow
- Since
- 1.53.0
It can be entirely omitted, and often the condition too. Clippy puts this lint in the complexity group, at the level warn.
- Code
needless_ifs- Severity
- warn
- Since
- 1.72.0
Assigning in the let statement is less repetitive. Clippy puts this lint in the style group, at the level warn.
- Code
needless_late_init- Severity
- warn
- Since
- 1.59.0
The additional lifetimes make the code look more complicated, while there is nothing out of the ordinary going on. Removing them leads to more readable code. Clippy puts this lint in the complexity group, at the level warn.
- Code
needless_lifetimes- Severity
- warn
This match block does nothing and might not be what the coder intended. Clippy puts this lint in the complexity group, at the level warn.
- Code
needless_match- Severity
- warn
- Since
- 1.61.0
The ?Sized bound is misleading because it cannot be satisfied by an unsized type Clippy puts this lint in the suspicious group, at the level warn.
- Code
needless_maybe_sized- Severity
- warn
- Since
- 1.81.0
Redundant code and improving readability. Clippy puts this lint in the complexity group, at the level warn.
- Code
needless_option_as_deref- Severity
- warn
- Since
- 1.57.0
Redundant code. take writes None to its argument. In this case the modification is useless as it’s a temporary that cannot be read from afterwards. Clippy puts this lint in the complexity group, at the level warn.
- Code
needless_option_take- Severity
- warn
- Since
- 1.62.0
Having superfluous parenthesis makes the code less readable overhead when reading. Clippy puts this lint in the style group, at the level warn.
- Code
needless_parens_on_range_literals- Severity
- warn
- Since
- 1.63.0
Less mut means less fights with the borrow checker. It can also lead to more opportunities for parallelization. Clippy puts this lint in the nursery group, at the level allow.
- Code
needless_pass_by_ref_mut- Severity
- allow
- Since
- 1.73.0
Taking arguments by reference is more flexible and can sometimes avoid unnecessary allocations. Clippy puts this lint in the pedantic group, at the level allow.
- Code
needless_pass_by_value- Severity
- allow
It’s unnecessary, omitting the pub entirely will give the same results. Clippy puts this lint in the style group, at the level warn.
- Code
needless_pub_self- Severity
- warn
- Since
- 1.72.0
There’s no reason to use ? to short-circuit when execution of the body will end there anyway. Clippy puts this lint in the complexity group, at the level warn.
- Code
needless_question_mark- Severity
- warn
- Since
- 1.51.0
Just iterating the collection itself makes the intent more clear and is probably faster because it eliminates the bounds check that is done when indexing. Clippy puts this lint in the style group, at the level warn.
- Code
needless_range_loop- Severity
- warn
It’s just unnecessary, and makes it look like there’s more escaping needed than is actually necessary. Clippy puts this lint in the pedantic group, at the level allow.
- Code
needless_raw_string_hashes- Severity
- allow
- Since
- 1.72.0
For consistent style by using simpler string literals whenever possible. Clippy puts this lint in the restriction group, at the level allow.
- Code
needless_raw_strings- Severity
- allow
- Since
- 1.72.0
Removing the return and semicolon will make the code more rusty. Clippy puts this lint in the style group, at the level warn.
- Code
needless_return- Severity
- warn
The return is unnecessary. Clippy puts this lint in the style group, at the level warn.
- Code
needless_return_with_question_mark- Severity
- warn
- Since
- 1.73.0
The function split is simpler and there is no performance difference in these cases, considering that both functions return a lazy iterator. Clippy puts this lint in the complexity group, at the level warn.
- Code
needless_splitn- Severity
- warn
- Since
- 1.59.0
If a binding is always cast to a different type when used, it would be clearer and more efficient to define it with the target type from the start. Clippy puts this lint in the nursery group, at the level allow.
- Code
needless_type_cast- Severity
- allow
- Since
- 1.94.0
This will cost resources (because the base has to be somewhere), and make the code less readable. Clippy puts this lint in the complexity group, at the level warn.
- Code
needless_update- Severity
- warn
These operators make it easy to forget that the underlying types actually allow not only three potential Orderings (Less, Equal, Greater) but also a fourth one (Uncomparable). This is especially easy to miss if the operator based comparison result is negated. Clippy puts this lint in the complexity group, at the level warn.
- Code
neg_cmp_op_on_partial_ord- Severity
- warn
It’s more readable to just negate. Clippy puts this lint in the style group, at the level warn.
- Code
neg_multiply- Severity
- warn
Features are supposed to be additive, and negatively-named features violate it. Clippy puts this lint in the cargo group, at the level allow.
- Code
negative_feature_names- Severity
- allow
- Since
- 1.57.0
This loop never loops, all it does is obfuscating the code. Clippy puts this lint in the correctness group, at the level deny.
- Code
never_loop- Severity
- deny
As a convention, new methods are used to make a new instance of a type. Clippy puts this lint in the style group, at the level warn.
- Code
new_ret_no_self- Severity
- warn
The user might expect to be able to use Default as the type can be constructed without arguments. Clippy puts this lint in the style group, at the level warn.
- Code
new_without_default- Severity
- warn
Unlike dead code, these statements are actually executed. However, as they have no effect, all they do is make the code less readable. Clippy puts this lint in the complexity group, at the level warn.
- Code
no_effect- Severity
- warn
It’s either a mistake or confusing. Clippy puts this lint in the suspicious group, at the level warn.
- Code
no_effect_replace- Severity
- warn
- Since
- 1.63.0
Unlike dead code, these bindings are actually executed. However, as they have no effect and shouldn’t be used further on, all they do is make the code less readable. Clippy puts this lint in the pedantic group, at the level allow.
- Code
no_effect_underscore_binding- Severity
- allow
- Since
- 1.58.0
The Rust ABI is not stable, but in many simple cases matches enough with the C ABI that it is possible to forget to add extern "C" to a function called from C. Changes to the Rust ABI can break this at any point. Clippy puts this lint in the pedantic group, at the level allow.
- Code
no_mangle_with_rust_abi- Severity
- allow
- Since
- 1.69.0
Yeah, we know, the 90’s called and wanted their charset back. Even so, there still are editors and other programs out there that don’t work well with Unicode. So if the code is meant to be used internationally, on multiple operating systems, or has other portability requirements, activating this lint could be useful. Clippy puts this lint in the restriction group, at the level allow.
- Code
non_ascii_literal- Severity
- allow
If both Clone and Copy are implemented, they must agree. This can done by dereferencing self in Clone’s implementation, which will avoid any possibility of the implementations becoming out of sync. Clippy puts this lint in the suspicious group, at the level warn.
- Code
non_canonical_clone_impl- Severity
- warn
- Since
- 1.72.0
If both PartialOrd and Ord are implemented, they must agree. This is commonly done by wrapping the result of cmp in Some for partial_cmp. Not doing this may silently introduce an error upon refactoring. Clippy puts this lint in the suspicious group, at the level warn.
- Code
non_canonical_partial_ord_impl- Severity
- warn
- Since
- 1.73.0
If there is only one condition, no need to wrap it into any or all combinators. Clippy puts this lint in the style group, at the level warn.
- Code
non_minimal_cfg- Severity
- warn
- Since
- 1.71.0
They will be converted into octal, creating potentially unintended file permissions. Clippy puts this lint in the correctness group, at the level deny.
- Code
non_octal_unix_permissions- Severity
- deny
- Since
- 1.53.0
It tries to detect fields that can cause a soundness issue when sent to another thread (e.g., Rc) while allowing !Send fields that are expected to exist in a Send type, such as raw pointers. Sending the struct to another thread effectively sends all of its fields, and the fields that do not implement Send can lead to soundness bugs such as data races when accessed in a thread that is different from the thread that created it. Clippy puts this lint in the nursery group, at the level allow.
- Code
non_send_fields_in_send_ty- Severity
- allow
- Since
- 1.57.0
Clippy puts this lint in the pedantic group, at the level allow.
- Code
non_std_lazy_statics- Severity
- allow
- Since
- 1.86.0
Converting from NonZero types to regular integer types and then back to NonZero types is less efficient and loses the type-safety guarantees provided by NonZero types. Using NonZero types consistently can lead to more optimized code and prevent certain classes of errors related to zero values. Clippy puts this lint in the restriction group, at the level allow.
- Code
non_zero_suggestions- Severity
- allow
- Since
- 1.83.0
Readability of boolean expressions suffers from unnecessary duplication. Clippy puts this lint in the pedantic group, at the level allow.
- Code
nonminimal_bool- Severity
- allow
NonNull::new_unchecked is an unsafe function, which we don’t need to call at all if we can instead use a mutable reference. Clippy puts this lint in the complexity group, at the level warn.
- Code
nonnull_unchecked_on_box_ptr- Severity
- warn
- Since
- 1.98.0
In the best case, the code will be harder to read than necessary. I don’t know the worst case. Clippy puts this lint in the correctness group, at the level deny.
- Code
nonsensical_open_options- Severity
- deny
Having non-conventional braces on well-stablished macros can be confusing when debugging, and they bring incosistencies with the rest of the ecosystem. Clippy puts this lint in the style group, at the level warn.
- Code
nonstandard_macro_braces- Severity
- warn
- Since
- 1.55.0
The function should almost definitely be marked unsafe, since for an arbitrary raw pointer, there is no way of telling for sure if it is valid. Clippy puts this lint in the correctness group, at the level deny.
- Code
not_unsafe_ptr_arg_deref- Severity
- deny
This can be written more clearly with if .. else .. Clippy puts this lint in the style group, at the level warn.
- Code
obfuscated_if_else- Severity
- warn
- Since
- 1.64.0
C and other languages support octal character escapes in strings, where a backslash is followed by up to three octal digits. For example, \033 stands for the ASCII character 27 (ESC). Rust does not support this notation, but has the escape code \0 which stands for a null byte/character, and any following digits do not form part of the escape sequence. Therefore, \033 is not a compiler error but the result may be surprising. Clippy puts this lint in the suspicious group, at the level warn.
- Code
octal_escapes- Severity
- warn
- Since
- 1.59.0
Because you usually call expect() on the Result directly to get a better error message. Clippy puts this lint in the style group, at the level warn.
- Code
ok_expect- Severity
- warn
It could contain a useless calculation and can make function simpler. Clippy puts this lint in the complexity group, at the level warn.
- Code
only_used_in_recursion- Severity
- warn
- Since
- 1.61.0
It is more idiomatic to dereference the other argument. Clippy puts this lint in the style group, at the level warn.
- Code
op_ref- Severity
- warn
This can be written more concisely by cloning the Option directly. Clippy puts this lint in the pedantic group, at the level allow.
- Code
option_as_ref_cloned- Severity
- allow
- Since
- 1.77.0
Readability, this can be written more concisely as _.as_deref(). Clippy puts this lint in the complexity group, at the level warn.
- Code
option_as_ref_deref- Severity
- warn
- Since
- 1.42.0
Unwrapping the result of option_env! will panic at run-time if the environment variable doesn’t exist, whereas env! catches it at compile-time. Clippy puts this lint in the correctness group, at the level deny.
- Code
option_env_unwrap- Severity
- deny
- Since
- 1.43.0
Option is like a collection of 0-1 things, so flatten automatically does this without suspicious-looking unwrap calls. Clippy puts this lint in the complexity group, at the level warn.
- Code
option_filter_map- Severity
- warn
- Since
- 1.53.0
Using the dedicated functions of the Option type is clearer and more concise than an if let expression. Clippy puts this lint in the nursery group, at the level allow.
- Code
option_if_let_else- Severity
- allow
- Since
- 1.47.0
Nothing. option_map_or_err_ok
This lint has been deprecated Clippy puts this lint in the deprecated group, at the level none.
- Code
option_map_or_err_ok- Severity
- none
- Since
- 1.87.0
Readability, this can be written more concisely as _.and_then(_). Clippy puts this lint in the style group, at the level warn.
- Code
option_map_or_none- Severity
- warn
Readability, this can be written more clearly with an if let statement Clippy puts this lint in the complexity group, at the level warn.
- Code
option_map_unit_fn- Severity
- warn
Option<_> represents an optional value. Option<Option<_>> represents an optional value which itself wraps an optional. This is logically the same thing as an optional value but has an unneeded extra level of wrapping. Clippy puts this lint in the pedantic group, at the level allow.
- Code
option_option- Severity
- allow
The function will always be called. This is only bad if it allocates or does some non-trivial amount of work. Clippy puts this lint in the nursery group, at the level allow.
- Code
or_fun_call- Severity
- allow
You should use .unwrap_or(…) instead for clarity. Clippy puts this lint in the complexity group, at the level warn.
- Code
or_then_unwrap- Severity
- warn
- Since
- 1.61.0
This will always panic at runtime. Clippy puts this lint in the correctness group, at the level deny.
- Code
out_of_bounds_indexing- Severity
- deny
This is most likely a logic bug. Clippy puts this lint in the pedantic group, at the level allow.
- Code
overly_complex_bool_expr- Severity
- allow
The borrowed types are usually more flexible, in that e.g. a Cow<'_, str> can accept both &str and String while Cow<'_, String> can only accept &String and String. In particular, &str is more general, because it allows for string literals while &String can only be borrowed from a heap-owned String). Clippy puts this lint in the style group, at the level warn.
- Code
owned_cow- Severity
- warn
- Since
- 1.87.0
This macro, or panics in general, may be unwanted in production code. Clippy puts this lint in the restriction group, at the level allow.
- Code
panic- Severity
- allow
- Since
- 1.40.0
For some codebases, it is desirable for functions of type result to return an error instead of crashing. Hence panicking macros should be avoided. Clippy puts this lint in the restriction group, at the level allow.
- Code
panic_in_result_fn- Severity
- allow
- Since
- 1.48.0
These checks will, by default, panic in debug builds rather than check whether the operation caused an overflow. Clippy puts this lint in the correctness group, at the level deny.
- Code
panicking_overflow_checks- Severity
- deny
If panicking is desired, an explicit panic!() should be used. Clippy puts this lint in the correctness group, at the level deny.
- Code
panicking_unwrap- Severity
- deny
Most types should either be: Clippy puts this lint in the restriction group, at the level allow.
- Code
partial_pub_fields- Severity
- allow
- Since
- 1.66.0
PartialEq::ne is required to always return the negated result of PartialEq::eq, which is exactly what the default implementation does. Therefore, there should never be any need to re-implement it. Clippy puts this lint in the complexity group, at the level warn.
- Code
partialeq_ne_impl- Severity
- warn
A programmer checking if some foo is None via a comparison foo == None is usually inspired from other programming languages (e.g. foo is None in Python). Checking if a value of type Option<T> is (not) equal to None in that way relies on T: PartialEq to do the comparison, which is unneeded. Clippy puts this lint in the style group, at the level warn.
- Code
partialeq_to_none- Severity
- warn
- Since
- 1.65.0
This doesn’t actually compare file extensions. Rather, ends_with compares the given argument to the last component of the path and checks if it matches exactly. Clippy puts this lint in the suspicious group, at the level warn.
- Code
path_ends_with_ext- Severity
- warn
- Since
- 1.74.0
Multiple .join() calls are usually easier to read than multiple .push calls across multiple statements. It might also be possible to use PathBuf::from instead. Clippy puts this lint in the restriction group, at the level allow.
- Code
pathbuf_init_then_push- Severity
- allow
- Since
- 1.82.0
It increases ownership hints in the code, and will guard against some changes in ownership. Clippy puts this lint in the restriction group, at the level allow.
- Code
pattern_type_mismatch- Severity
- allow
- Since
- 1.47.0
On Unix platforms this results in the file being world writable, equivalent to chmod a+w <file>. Clippy puts this lint in the suspicious group, at the level warn.
- Code
permissions_set_readonly_false- Severity
- warn
- Since
- 1.68.0
The addresses are only useful in very specific contexts, and certain projects may want to keep addresses of certain data structures or functions from prying hacker eyes as an additional line of security. Clippy puts this lint in the restriction group, at the level allow.
- Code
pointer_format- Severity
- allow
- Since
- 1.89.0
nomem forbids any reads or writes to memory and passing a pointer suggests that either of those will happen. Clippy puts this lint in the suspicious group, at the level warn.
- Code
pointers_in_nomem_asm_block- Severity
- warn
- Since
- 1.81.0
It lints if an array element is a binary operator expression and it lies on two lines. This could lead to unexpected results. Clippy puts this lint in the correctness group, at the level deny.
- Code
possible_missing_comma- Severity
- deny
This is probably some refactoring remnant, even if the code is correct, it might look confusing. Clippy puts this lint in the suspicious group, at the level warn.
- Code
possible_missing_else- Severity
- warn
- Since
- 1.91.0
It catches a mixed usage of arithmetic and bit shifting/combining operators, as well as method calls applied to closures. Not everyone knows the precedence of those operators by heart, so expressions like these may trip others trying to reason about the code. Clippy puts this lint in the complexity group, at the level warn.
- Code
precedence- Severity
- warn
Not everyone knows the precedence of those operators by heart, so expressions like these may trip others trying to reason about the code. Clippy puts this lint in the restriction group, at the level allow.
- Code
precedence_bits- Severity
- allow
- Since
- 1.86.0
Using a print macro is likely unintentional since formatting traits should write to the Formatter, not stdout/stderr. Clippy puts this lint in the suspicious group, at the level warn.
- Code
print_in_format_impl- Severity
- warn
- Since
- 1.61.0
Using literals as println! args is inefficient (c.f., https://github.com/matthiaskrgr/rust-str-bench) and unnecessary (i.e., just put the literal in the format string) Clippy puts this lint in the style group, at the level warn.
- Code
print_literal- Severity
- warn
The purpose of this lint is to catch debugging remnants. People often print on stderr while debugging an application and might forget to remove those prints afterward. Clippy puts this lint in the restriction group, at the level allow.
- Code
print_stderr- Severity
- allow
- Since
- 1.50.0
The purpose of this lint is to catch debugging remnants. People often print on stdout while debugging an application and might forget to remove those prints afterward. Clippy puts this lint in the restriction group, at the level allow.
- Code
print_stdout- Severity
- allow
You should use println!() instead, which appends the newline. Clippy puts this lint in the style group, at the level warn.
- Code
print_with_newline- Severity
- warn
You should use println!(), which is simpler. Clippy puts this lint in the style group, at the level warn.
- Code
println_empty_string- Severity
- warn
It will also suggest you replace .clone() calls with the appropriate .to_owned()/to_string() calls. Requiring the argument to be of the specific type makes the function less useful for no benefit; slices in the form of &[T] or &str usually suffice and can be obtained from other types, too. Clippy puts this lint in the style group, at the level warn.
- Code
ptr_arg- Severity
- warn
Though as casts between raw pointers are not terrible, pointer::cast is safer because it cannot accidentally change the pointer’s mutability, nor cast the pointer to other types like usize. Clippy puts this lint in the pedantic group, at the level allow.
- Code
ptr_as_ptr- Severity
- allow
- Since
- 1.51.0
Though as casts between raw pointers are not terrible, pointer::cast_mut and pointer::cast_const are safer because they cannot accidentally cast the pointer to another type. Or, when null pointers are involved, null() and null_mut() can be used directly. Clippy puts this lint in the pedantic group, at the level allow.
- Code
ptr_cast_constness- Severity
- allow
- Since
- 1.72.0
ptr::eq can be used to compare &T references (which coerce to *const T implicitly) by their address rather than comparing the values they point to. Clippy puts this lint in the style group, at the level warn.
- Code
ptr_eq- Severity
- warn
- Since
- 1.49.0
The add and sub methods more accurately express the intent. Clippy puts this lint in the pedantic group, at the level allow.
- Code
ptr_offset_by_literal- Severity
- allow
- Since
- 1.94.0
If we’re always increasing the pointer address, we can avoid the numeric cast by using the add method instead. Clippy puts this lint in the complexity group, at the level warn.
- Code
ptr_offset_with_cast- Severity
- warn
- Since
- 1.30.0
Nothing. pub_enum_variant_names
This lint has been deprecated Clippy puts this lint in the deprecated group, at the level none.
- Code
pub_enum_variant_names- Severity
- none
- Since
- 1.54.0
Fields prefixed with an _ are inferred as unused, which suggests it should not be marked as pub, because marking it as pub infers it will be used. Clippy puts this lint in the pedantic group, at the level allow.
- Code
pub_underscore_fields- Severity
- allow
- Since
- 1.77.0
A project may wish to limit pub use instances to prevent unintentional exports, or to encourage placing exported items directly in public modules. Clippy puts this lint in the restriction group, at the level allow.
- Code
pub_use- Severity
- allow
- Since
- 1.62.0
Consistency. Use it or don’t, just be consistent about it. Clippy puts this lint in the restriction group, at the level allow.
- Code
pub_with_shorthand- Severity
- allow
- Since
- 1.72.0
Consistency. Use it or don’t, just be consistent about it. Clippy puts this lint in the restriction group, at the level allow.
- Code
pub_without_shorthand- Severity
- allow
- Since
- 1.72.0
Using the ? operator is shorter and more idiomatic. Clippy puts this lint in the style group, at the level warn.
- Code
question_mark- Severity
- warn
Sometimes code wants to avoid the ? operator because for instance a local block requires a macro to re-throw errors to attach additional information to the error. Clippy puts this lint in the restriction group, at the level allow.
- Code
question_mark_used- Severity
- allow
- Since
- 1.69.0
The code is more readable with an exclusive range like x..y. Clippy puts this lint in the pedantic group, at the level allow.
- Code
range_minus_one- Severity
- allow
The code is more readable with an inclusive range like x..=y. Clippy puts this lint in the pedantic group, at the level allow.
- Code
range_plus_one- Severity
- allow
Nothing. range_step_by_zero
This lint has been deprecated Clippy puts this lint in the deprecated group, at the level none.
- Code
range_step_by_zero- Severity
- none
The code is better expressed with .enumerate(). Clippy puts this lint in the complexity group, at the level warn.
- Code
range_zip_with_len- Severity
- warn
Expressions such as Rc<String> usually have no advantage over Rc<str>, since it is larger and involves an extra level of indirection, and doesn’t implement Borrow<str>. Clippy puts this lint in the restriction group, at the level allow.
- Code
rc_buffer- Severity
- allow
- Since
- 1.48.0
This will create elem once and clone it len times - doing so with Arc/Rc/Weak is a bit misleading, as it will create references to the same pointer, rather than different instances. Clippy puts this lint in the suspicious group, at the level warn.
- Code
rc_clone_in_vec_init- Severity
- warn
- Since
- 1.63.0
Rc is used in single thread and Mutex is used in multi thread. Consider using Rc<RefCell<T>> in single thread or Arc<Mutex<T>> in multi thread. Clippy puts this lint in the restriction group, at the level allow.
- Code
rc_mutex- Severity
- allow
- Since
- 1.55.0
The operation will always fail at runtime no matter what the user enters, thus making it a useless operation. Clippy puts this lint in the correctness group, at the level deny.
- Code
read_line_without_trim- Severity
- deny
- Since
- 1.73.0
Especially in the case of a call to with_capacity, this lint warns that read gets the number of bytes from the Vec’s length, not its capacity. Reading zero bytes is almost certainly not the intended behavior. Clippy puts this lint in the nursery group, at the level allow.
- Code
read_zero_byte_vec- Severity
- allow
- Since
- 1.63.0
The write portion of RwLock is exclusive, meaning that no other thread can access the lock while this writer is active. Clippy puts this lint in the perf group, at the level warn.
- Code
readonly_write_lock- Severity
- warn
- Since
- 1.73.0
Display) with a recursive call to itself which uses self as a parameter. This is typically done indirectly with the write! macro or with to_string(). This will lead to infinite recursion and a stack overflow. Clippy puts this lint in the correctness group, at the level deny.
- Code
recursive_format_impl- Severity
- deny
- Since
- 1.48.0
Expressions such as Rc<&T>, Rc<Rc<T>>, Rc<Arc<T>>, Rc<Box<T>>, Arc<&T>, Arc<Rc<T>>, Arc<Arc<T>>, Arc<Box<T>>, Box<&T>, Box<Rc<T>>, Box<Arc<T>>, Box<Box<T>>, add an unnecessary level of indirection. Clippy puts this lint in the perf group, at the level warn.
- Code
redundant_allocation- Severity
- warn
- Since
- 1.44.0
The as_str() conversion is pointless and can be removed for simplicity and cleanliness. Clippy puts this lint in the complexity group, at the level warn.
- Code
redundant_as_str- Severity
- warn
- Since
- 1.74.0
It is simpler and more efficient to use the future directly. Clippy puts this lint in the complexity group, at the level warn.
- Code
redundant_async_block- Severity
- warn
- Since
- 1.70.0
In all cases, all works fine and can often make code simpler, as you possibly won’t need to convert from say a Vec to a slice by dereferencing. Clippy puts this lint in the complexity group, at the level warn.
- Code
redundant_at_rest_pattern- Severity
- warn
- Since
- 1.72.0
It is not always possible for the compiler to eliminate useless allocations and deallocations generated by redundant clone()s. Clippy puts this lint in the nursery group, at the level allow.
- Code
redundant_clone- Severity
- allow
- Since
- 1.32.0
Needlessly creating a closure adds code for no benefit and gives the optimizer more work. Clippy puts this lint in the style group, at the level warn.
- Code
redundant_closure- Severity
- warn
It is unnecessarily adding to the expression’s complexity. Clippy puts this lint in the complexity group, at the level warn.
- Code
redundant_closure_call- Severity
- warn
It’s unnecessary to create the closure. Clippy puts this lint in the pedantic group, at the level allow.
- Code
redundant_closure_for_method_calls- Severity
- allow
- Since
- 1.35.0
Only one of the comparisons has any effect on the result, the programmer probably intended to flip one of the comparison operators, or compare a different value entirely. Clippy puts this lint in the correctness group, at the level deny.
- Code
redundant_comparisons- Severity
- deny
- Since
- 1.73.0
The else block adds unnecessary indentation and verbosity. Clippy puts this lint in the pedantic group, at the level allow.
- Code
redundant_else- Severity
- allow
- Since
- 1.50.0
These prefixes and suffixes have no significant meaning. Clippy puts this lint in the cargo group, at the level allow.
- Code
redundant_feature_names- Severity
- allow
- Since
- 1.57.0
If the field and variable names are the same, the field name is redundant. Clippy puts this lint in the style group, at the level warn.
- Code
redundant_field_names- Severity
- warn
It’s more complex and much less readable. Making it part of the pattern can improve exhaustiveness checking as well. Clippy puts this lint in the complexity group, at the level warn.
- Code
redundant_guards- Severity
- warn
- Since
- 1.73.0
It is not always possible for the compiler to eliminate useless allocations and deallocations generated by redundant clone()s. Clippy puts this lint in the perf group, at the level warn.
- Code
redundant_iter_cloned- Severity
- warn
- Since
- 1.92.0
Redundant redefinitions of local bindings do not change behavior other than variable’s lifetimes and are likely to be unintended. Clippy puts this lint in the suspicious group, at the level warn.
- Code
redundant_locals- Severity
- warn
- Since
- 1.73.0
It’s almost always more readable to just use direct bindings. Clippy puts this lint in the style group, at the level warn.
- Code
redundant_pattern- Severity
- warn
It’s more concise and clear to just use the proper utility function or using the condition directly Clippy puts this lint in the style group, at the level warn.
- Code
redundant_pattern_matching- Severity
- warn
- Since
- 1.31.0
Writing pub(crate) is misleading when it’s redundant due to the parent module’s visibility. Clippy puts this lint in the nursery group, at the level allow.
- Code
redundant_pub_crate- Severity
- allow
- Since
- 1.44.0
It unnecessarily adds complexity to the expression. Clippy puts this lint in the complexity group, at the level warn.
- Code
redundant_slicing- Severity
- warn
- Since
- 1.51.0
Adding 'static to every reference can create very complicated types. Clippy puts this lint in the style group, at the level warn.
- Code
redundant_static_lifetimes- Severity
- warn
- Since
- 1.37.0
This is redundant because test functions are already annotated with #[test]. Moreover, it clutters the output of cargo test since test functions are expanded as module::tests::test_use_case in the output. Without the redundant prefix, the output becomes module::tests::use_case, which is more readable. Clippy puts this lint in the restriction group, at the level allow.
- Code
redundant_test_prefix- Severity
- allow
- Since
- 1.88.0
Code without type annotations is shorter and in most cases more idiomatic and easier to modify. Clippy puts this lint in the restriction group, at the level allow.
- Code
redundant_type_annotations- Severity
- allow
- Since
- 1.72.0
Using as casts may result in silently changing mutability or type. Clippy puts this lint in the pedantic group, at the level allow.
- Code
ref_as_ptr- Severity
- allow
- Since
- 1.78.0
The address-of operator at the use site is clearer about the need for a reference. Clippy puts this lint in the pedantic group, at the level allow.
- Code
ref_binding_to_reference- Severity
- allow
- Since
- 1.54.0
More flexibility, better memory optimization, and more idiomatic Rust code. Clippy puts this lint in the pedantic group, at the level allow.
- Code
ref_option- Severity
- allow
- Since
- 1.83.0
Since & is Copy, it’s useless to have a reference on Option<&T>. Clippy puts this lint in the pedantic group, at the level allow.
- Code
ref_option_ref- Severity
- allow
- Since
- 1.49.0
The ref keyword can be confusing for people unfamiliar with it, and often it is more concise to use & instead. Clippy puts this lint in the restriction group, at the level allow.
- Code
ref_patterns- Severity
- allow
- Since
- 1.71.0
Compiling a regex is a much more expensive operation than using one, and a compiled regex can be used multiple times. This is documented as an antipattern on the regex documentation Clippy puts this lint in the perf group, at the level warn.
- Code
regex_creation_in_loops- Severity
- warn
- Since
- 1.84.0
This lint has been deprecated Clippy puts this lint in the deprecated group, at the level none.
- Code
regex_macro- Severity
- none
- Since
- 1.47.0