Many codebases have their own style when it comes to importing, but one that is seldom used is using absolute paths everywhere. This is generally considered unidiomatic, and you should add a use statement. Clippy puts this lint in the restriction group, at the level allow.
- Code
absolute_paths- Severity
- allow
- Since
- 1.73.0
Only integer and boolean types are checked. An expression like min <= x may misleadingly imply that it is possible for x to be less than the minimum. Expressions like max < x are probably mistakes. Clippy puts this lint in the correctness group, at the level deny.
- Code
absurd_extreme_comparisons- Severity
- deny
Crates which have no_std compatibility and may optionally require alloc may wish to ensure types are imported from core to ensure disabling alloc does not cause the crate to fail to compile. This lint is also useful for crates migrating to become no_std compatible. Clippy puts this lint in the restriction group, at the level allow.
- Code
alloc_instead_of_core- Severity
- allow
- Since
- 1.64.0
#[expect] attributes suppress the lint emission, but emit a warning, if the expectation is unfulfilled. This can be useful to be notified when the lint is no longer triggered. Clippy puts this lint in the restriction group, at the level allow.
- Code
allow_attributes- Severity
- allow
- Since
- 1.70.0
Justifying each allow helps readers understand the reasoning, and may allow removing allow attributes if their purpose is obsolete. Clippy puts this lint in the restriction group, at the level allow.
- Code
allow_attributes_without_reason- Severity
- allow
- Since
- 1.61.0
This ('a'..'z') is almost certainly a typo meant to include all letters. Clippy puts this lint in the suspicious group, at the level warn.
- Code
almost_complete_range- Severity
- warn
- Since
- 1.68.0
This looks like a failed attempt to swap. Clippy puts this lint in the correctness group, at the level deny.
- Code
almost_swapped- Severity
- deny
Usually, the definition in the standard library is more precise than what people come up with. If you find that your definition is actually more precise, please file a Rust issue. Clippy puts this lint in the correctness group, at the level deny.
- Code
approx_constant- Severity
- deny
Keeping a consistent ordering throughout the codebase helps with working as a team, and possibly improves maintainability of the codebase. The idea is that by defining a consistent and enforceable rule for how source files are structured, less time will be wasted during reviews on a topic that is (under most circumstances) not relevant to the logic implemented in the code. Sometimes this will be referred to as “bikeshedding”. Clippy puts this lint in the restriction group, at the level allow.
- Code
arbitrary_source_item_ordering- Severity
- allow
- Since
- 1.84.0
For integers, overflow will trigger a panic in debug builds or wrap the result in release mode; division by zero will cause a panic in either mode. As a result, it is desirable to explicitly call checked, wrapping or saturating arithmetic methods. Clippy puts this lint in the restriction group, at the level allow.
- Code
arithmetic_side_effects- Severity
- allow
- Since
- 1.64.0
as conversions will perform many kinds of conversions, including silently lossy conversions and dangerous coercions. There are cases when it makes sense to use as, so the lint is Allow by default. Clippy puts this lint in the restriction group, at the level allow.
- Code
as_conversions- Severity
- allow
- Since
- 1.41.0
The conversion might include a dangerous cast that might go undetected due to the type being inferred. Clippy puts this lint in the restriction group, at the level allow.
- Code
as_pointer_underscore- Severity
- allow
- Since
- 1.85.0
Since as_ptr takes a &self, the pointer won’t have write permissions unless interior mutability is used, making it unlikely that having it as a mutable pointer is correct. Clippy puts this lint in the nursery group, at the level allow.
- Code
as_ptr_cast_mut- Severity
- allow
- Since
- 1.66.0
The conversion might include lossy conversion or a dangerous cast that might go undetected due to the type being inferred. Clippy puts this lint in the restriction group, at the level allow.
- Code
as_underscore- Severity
- allow
- Since
- 1.63.0
A boolean assertion only reports that the emptiness check failed. It does not show what the asserted value contained. Clippy puts this lint in the pedantic group, at the level allow.
- Code
assert_is_empty- Severity
- allow
- Since
- 1.98.0
Will be optimized out by the compiler or should probably be replaced by a panic!() or unreachable!() Clippy puts this lint in the style group, at the level warn.
- Code
assertions_on_constants- Severity
- warn
- Since
- 1.34.0
This form of assertion does not show any of the information present in the Result other than which variant it isn’t. Clippy puts this lint in the restriction group, at the level allow.
- Code
assertions_on_result_states- Severity
- allow
- Since
- 1.64.0
These can be written as the shorter a op= b. Clippy puts this lint in the style group, at the level warn.
- Code
assign_op_pattern- Severity
- warn
This lint has been deprecated Clippy puts this lint in the deprecated group, at the level none.
- Code
assign_ops- Severity
- none
- Since
- 1.30.0
Custom Clone::clone_from() or ToOwned::clone_into implementations allow the objects to share resources and therefore avoid allocations. Clippy puts this lint in the pedantic group, at the level allow.
- Code
assigning_clones- Severity
- allow
- Since
- 1.78.0
An await is likely missing. Clippy puts this lint in the correctness group, at the level deny.
- Code
async_yields_async- Severity
- deny
- Since
- 1.48.0
There are some types which are perfectly safe to use concurrently from a memory access perspective, but that will cause bugs at runtime if they are held in such a way. Clippy puts this lint in the suspicious group, at the level warn.
- Code
await_holding_invalid_type- Severity
- warn
- Since
- 1.62.0
The Mutex types found in std::sync and parking_lot are not designed to operate in an async context across await points. Clippy puts this lint in the suspicious group, at the level warn.
- Code
await_holding_lock- Severity
- warn
- Since
- 1.45.0
RefCell refs only check for exclusive mutable access at runtime. Holding a RefCell ref across an await suspension point risks panics from a mutable ref shared while other refs are outstanding. Clippy puts this lint in the suspicious group, at the level warn.
- Code
await_holding_refcell_ref- Severity
- warn
- Since
- 1.49.0
If the bits that the comparison cares about are always set to zero or one by the bit mask, the comparison is constant true or false (depending on mask, compared value, and operators). Clippy puts this lint in the correctness group, at the level deny.
- Code
bad_bit_mask- Severity
- deny
To ensure use of little-endian or the target’s endianness rather than big-endian. Clippy puts this lint in the restriction group, at the level allow.
- Code
big_endian_bytes- Severity
- allow
- Since
- 1.72.0
This can be written more concisely as _.map(|x| y) or _.map_err(|x| y). Clippy puts this lint in the complexity group, at the level warn.
- Code
bind_instead_of_map- Severity
- warn
- Since
- 1.45.0
Restriction lints sometimes are in contrast with other lints or even go against idiomatic rust. These lints should only be enabled on a lint-by-lint basis and with careful consideration. Clippy puts this lint in the suspicious group, at the level warn.
- Code
blanket_clippy_restriction_lints- Severity
- warn
- Since
- 1.47.0
This lint only triggers on the 2021 edition and older. It is unusual to write { expr } when you could just have written expr, and it is unlikely that anyone would write that for any reason other than wanting temporaries in expr to be dropped before executing the body of the match/if let/while statement. However, prior to the 2024 edition, wrapping the scrutinee in a block did not drop temporaries before the body executes. Clippy puts this lint in the suspicious group, at the level warn.
- Code
block_scrutinee- Severity
- warn
- Since
- 1.98.0
Style, using blocks in the condition makes it hard to read. Clippy puts this lint in the style group, at the level warn.
- Code
blocks_in_conditions- Severity
- warn
- Since
- 1.45.0
It is shorter to use the equivalent. Clippy puts this lint in the style group, at the level warn.
- Code
bool_assert_comparison- Severity
- warn
- Since
- 1.53.0
Unnecessary code. Clippy puts this lint in the complexity group, at the level warn.
- Code
bool_comparison- Severity
- warn
Coercion or from() is another way to convert bool to a number. Both methods are guaranteed to return 1 for true, and 0 for false. Clippy puts this lint in the pedantic group, at the level allow.
- Code
bool_to_int_with_if- Severity
- allow
- Since
- 1.65.0
This would improve readability and avoid creating a reference that points to an uninitialized value or unaligned place. Read the &raw explanation in the Reference for more information. Clippy puts this lint in the pedantic group, at the level allow.
- Code
borrow_as_ptr- Severity
- allow
- Since
- 1.60.0
Dereferencing and then borrowing a reference value has no effect in most cases. Clippy puts this lint in the complexity group, at the level warn.
- Code
borrow_deref_ref- Severity
- warn
- Since
- 1.63.0
Named constants are copied at every use site which means any change to their value will be lost after the newly created value is dropped. e.g. Clippy puts this lint in the style group, at the level warn.
- Code
borrow_interior_mutable_const- Severity
- warn
Check the Box documentation for more information. A &Box<T> parameter requires the function caller to box T first before passing it to a function. Using &T defines a concrete type for the parameter and generalizes the function, this would also auto-deref to &T at the function call site if passed a &Box<T>. Clippy puts this lint in the complexity group, at the level warn.
- Code
borrowed_box- Severity
- warn
Check the Box documentation for more information. Collections already keeps their contents in a separate area on the heap. So if you Box them, you just add another level of indirection without any benefit whatsoever. Clippy puts this lint in the perf group, at the level warn.
- Code
box_collection- Severity
- warn
- Since
- 1.57.0
Box::default() is equivalent and more concise. Clippy puts this lint in the style group, at the level warn.
- Code
box_default- Severity
- warn
- Since
- 1.66.0
This is an unnecessary allocation, and bad for performance. It is only necessary to allocate if you wish to move the box into something. Clippy puts this lint in the perf group, at the level warn.
- Code
boxed_local- Severity
- warn
Duplicate code is less maintainable. Clippy puts this lint in the nursery group, at the level allow.
- Code
branches_sharing_code- Severity
- allow
- Since
- 1.53.0
This gives surprising type errors. Clippy puts this lint in the style group, at the level warn.
- Code
builtin_type_shadow- Severity
- warn
While it might look like this will allow peeking on the first element of an iterator without consuming it and without consuming the iterator itself, it will in practice consume the first element. Clippy puts this lint in the suspicious group, at the level warn.
- Code
by_ref_peekable_peek- Severity
- warn
- Since
- 1.98.0
Potentially makes the string harder to read. Clippy puts this lint in the style group, at the level warn.
- Code
byte_char_slices- Severity
- warn
- Since
- 1.81.0
str::bytes().count() is longer and may not be as performant as using str::len(). Clippy puts this lint in the complexity group, at the level warn.
- Code
bytes_count_to_len- Severity
- warn
- Since
- 1.62.0
.as_bytes().get() is more efficient and more readable. Clippy puts this lint in the style group, at the level warn.
- Code
bytes_nth- Severity
- warn
- Since
- 1.52.0
See: https://rust-lang.github.io/api-guidelines/documentation.html#cargotoml-includes-all-common-metadata-c-metadata It will be more difficult for users to discover the purpose of the crate, and key information related to it. Clippy puts this lint in the cargo group, at the level allow.
- Code
cargo_common_metadata- Severity
- allow
- Since
- 1.32.0
ends_with is case-sensitive and may not detect files with a valid extension. Clippy puts this lint in the pedantic group, at the level allow.
- Code
case_sensitive_file_extension_comparisons- Severity
- allow
- Since
- 1.51.0
The unsigned_abs() method avoids panic when called on the MIN value. Clippy puts this lint in the suspicious group, at the level warn.
- Code
cast_abs_to_unsigned- Severity
- warn
- Since
- 1.62.0
The cast is easily confused with casting a c-like enum value to an integer. Clippy puts this lint in the suspicious group, at the level warn.
- Code
cast_enum_constructor- Severity
- warn
- Since
- 1.61.0
The resulting integral value will not match the value of the variant it came from. Clippy puts this lint in the suspicious group, at the level warn.
- Code
cast_enum_truncation- Severity
- warn
- Since
- 1.61.0
Rust’s as keyword will perform many kinds of conversions, including silently lossy conversions. Conversion functions such as i32::from will only perform lossless conversions. Using the conversion functions prevents conversions from becoming silently lossy if the input types ever change, and makes it clear for people reading the code that the conversion is lossless. Clippy puts this lint in the pedantic group, at the level allow.
- Code
cast_lossless- Severity
- allow
NaNs are cast into zero, so one could simply use this and make the code more readable. The lint could also hint at a programmer error. Clippy puts this lint in the suspicious group, at the level warn.
- Code
cast_nan_to_int- Severity
- warn
- Since
- 1.66.0
This is expected behavior, so the cast is Allow by default. It suggests user either explicitly ignore the lint, or use try_from() and handle the truncation, default, or panic explicitly. In some problem domains, it is good practice to avoid truncation. This lint can be activated to help assess where additional checks could be beneficial. Clippy puts this lint in the pedantic group, at the level allow.
- Code
cast_possible_truncation- Severity
- allow
Performing such a cast is a no-op for the compiler (that is, nothing is changed at the bit level), and the binary representation of the value is reinterpreted. This can cause wrapping if the value is too big for the target signed type. However, the cast works as defined, so this lint is Allow by default. While such a cast is not bad in itself, the results can be surprising when this is not the intended behavior: Clippy puts this lint in the pedantic group, at the level allow.
- Code
cast_possible_wrap- Severity
- allow
This possible rounding is to be expected, so this lint is Allow by default. It’s not bad at all. But in some applications it can be helpful to know where precision loss can take place. This lint can help find those places in the code. Clippy puts this lint in the pedantic group, at the level allow.
- Code
cast_precision_loss- Severity
- allow
Dereferencing the resulting pointer may be undefined behavior. Clippy puts this lint in the pedantic group, at the level allow.
- Code
cast_ptr_alignment- Severity
- allow
In this case, negative values wrap around to large positive values, which can be quite surprising in practice. However, since the cast works as defined, this lint is Allow by default. Possibly surprising results. You can activate this lint as a one-time check to see where numeric wrapping can arise. Clippy puts this lint in the pedantic group, at the level allow.
- Code
cast_sign_loss- Severity
- allow
The produced raw pointer to a slice does not update its length metadata. The produced pointer will point to a different number of bytes than the original pointer because the length metadata of a raw slice pointer is in elements rather than bytes. Producing a slice reference from the raw pointer will either create a slice with less data (which can be surprising) or create a slice with more data and cause Undefined Behavior. Clippy puts this lint in the correctness group, at the level deny.
- Code
cast_slice_different_sizes- Severity
- deny
- Since
- 1.61.0
This can result in multiple &mut references to the same location when only a pointer is required. ptr::slice_from_raw_parts is a safe alternative that doesn’t require the same safety requirements to be upheld. Clippy puts this lint in the suspicious group, at the level warn.
- Code
cast_slice_from_raw_parts- Severity
- warn
- Since
- 1.65.0
(i.e., #[cfg(not(test))]) This may give the false impression that a codebase has 100% coverage, yet actually has untested code. Enabling this also guards against excessive mockery as well, which is an anti-pattern. Clippy puts this lint in the restriction group, at the level allow.
- Code
cfg_not_test- Severity
- allow
- Since
- 1.81.0
A character (more specifically, a Unicode scalar value) that is yielded by str::chars can take up multiple bytes, so a character position does not necessarily have the same byte index at which the character is stored. Thus, using the character position where a byte index is expected can unexpectedly return wrong values or panic when the string consists of multibyte characters. Clippy puts this lint in the correctness group, at the level deny.
- Code
char_indices_as_byte_indices- Severity
- deny
- Since
- 1.88.0
In general, casting values to smaller types is error-prone and should be avoided where possible. In the particular case of converting a character literal to u8, it is easy to avoid by just using a byte literal instead. As an added bonus, b'a' is also slightly shorter than 'a' as u8. Clippy puts this lint in the complexity group, at the level warn.
- Code
char_lit_as_u8- Severity
- warn
Readability, this can be written more concisely as _.ends_with(_). Clippy puts this lint in the style group, at the level warn.
- Code
chars_last_cmp- Severity
- warn
Readability, this can be written more concisely as _.starts_with(_). Clippy puts this lint in the style group, at the level warn.
- Code
chars_next_cmp- Severity
- warn
Reduces the readability of statements & is error prone. Clippy puts this lint in the pedantic group, at the level allow.
- Code
checked_conversions- Severity
- allow
- Since
- 1.37.0
as_chunks provides better ergonomics and type safety by returning arrays instead of slices. It was stabilized in Rust 1.88. Clippy puts this lint in the style group, at the level warn.
- Code
chunks_exact_to_as_chunks- Severity
- warn
- Since
- 1.93.0
This creates an unnecessary iterator that is dropped immediately. Clippy puts this lint in the nursery group, at the level allow.
- Code
clear_with_drain- Severity
- allow
- Since
- 1.70.0
The only reason Copy types implement Clone is for generics, not for using the clone method on a concrete type. Clippy puts this lint in the complexity group, at the level warn.
- Code
clone_on_copy- Severity
- warn
Calling .clone() on an Rc, Arc, or Weak can obscure the fact that only the pointer is being cloned, not the underlying data. Clippy puts this lint in the restriction group, at the level allow.
- Code
clone_on_ref_ptr- Severity
- allow
copied() is better because it guarantees that the type being cloned implements Copy. Clippy puts this lint in the pedantic group, at the level allow.
- Code
cloned_instead_of_copied- Severity
- allow
- Since
- 1.53.0
Clippy puts this lint in the perf group, at the level warn.
- Code
cloned_ref_to_slice_refs- Severity
- warn
- Since
- 1.89.0
It’s easier and more readable to use the inherent .is_null() method instead Clippy puts this lint in the style group, at the level warn.
- Code
cmp_null- Severity
- warn
The comparison can operate on a reference, so creating an owned value effectively throws it away directly afterwards, which is needlessly consuming code and heap space. Clippy puts this lint in the perf group, at the level warn.
- Code
cmp_owned- Severity
- warn
The intention is usually to get a reference to the dyn Any the value dereferences to, rather than coercing a reference to the container itself to &dyn Any. Clippy puts this lint in the nursery group, at the level allow.
- Code
coerce_container_to_any- Severity
- allow
- Since
- 1.89.0
Ideally, we would like to be able to measure how hard a function is to understand given its context (what we call its Cognitive Complexity). But that’s not what this lint does. See “Known problems” Clippy puts this lint in the restriction group, at the level allow.
- Code
cognitive_complexity- Severity
- allow
- Since
- 1.35.0
Each if-statement adds one level of nesting, which makes code look more complex than it really is. Clippy puts this lint in the pedantic group, at the level allow.
- Code
collapsible_else_if- Severity
- allow
- Since
- 1.51.0
Each if-statement adds one level of nesting, which makes code look more complex than it really is. Clippy puts this lint in the style group, at the level warn.
- Code
collapsible_if- Severity
- warn
It is unnecessarily verbose and complex. Clippy puts this lint in the style group, at the level warn.
- Code
collapsible_match- Severity
- warn
- Since
- 1.50.0
Consecutive str::replace calls scan the string multiple times with repetitive code. Clippy puts this lint in the perf group, at the level warn.
- Code
collapsible_str_replace- Severity
- warn
- Since
- 1.65.0
Putting effort into constructing a collection but then never querying it might indicate that the author forgot to do whatever they intended to do with the collection. Example: Clone a vector, sort it for iteration, but then mistakenly iterate the original vector instead. Clippy puts this lint in the nursery group, at the level allow.
- Code
collection_is_never_read- Severity
- allow
- Since
- 1.70.0
if is not guaranteed to be exhaustive and conditionals can get repetitive Clippy puts this lint in the pedantic group, at the level allow.
- Code
comparison_chain- Severity
- allow
- Since
- 1.40.0
Some structures can answer .is_empty() much faster than checking for equality. So it is good to get into the habit of using .is_empty(), and having it is cheap. Besides, it makes the intent clearer than a manual comparison in some contexts. Clippy puts this lint in the style group, at the level warn.
- Code
comparison_to_empty- Severity
- warn
- Since
- 1.49.0
Casting a function pointer to an integer can have surprising results and can occur accidentally if parentheses are omitted from a function call. If you aren’t doing anything low-level with function pointers then you can opt out of casting functions to integers in order to avoid mistakes. Alternatively, you can use this lint to audit all uses of function pointer casts in your code. Clippy puts this lint in the suspicious group, at the level warn.
- Code
confusing_method_to_numeric_cast- Severity
- warn
- Since
- 1.89.0
String literals and constant values are known at compile time. Checking if they are empty will always return the same value. This might not be the intention of the expression. Clippy puts this lint in the suspicious group, at the level warn.
- Code
const_is_empty- Severity
- warn
- Since
- 1.79.0
Implicit copies can be confusing when working with iterator combinators. Clippy puts this lint in the pedantic group, at the level allow.
- Code
copy_iterator- Severity
- allow
- Since
- 1.30.0
crate refers to the macro call’s crate, whereas $crate refers to the macro definition’s crate. Rarely is the former intended. See: https://doc.rust-lang.org/reference/macros-by-example.html#hygiene Clippy puts this lint in the suspicious group, at the level warn.
- Code
crate_in_macro_def- Severity
- warn
- Since
- 1.62.0
Sometimes std::fs::create_dir is mistakenly chosen over std::fs::create_dir_all, resulting in failure when more than one directory needs to be created or when the directory already exists. Crates which never need to specifically create a single directory may wish to prevent this mistake. Clippy puts this lint in the restriction group, at the level allow.
- Code
create_dir- Severity
- allow
- Since
- 1.48.0
It’s easy to mistakenly transmute between a type and a pointer to that type. Clippy puts this lint in the suspicious group, at the level warn.
- Code
crosspointer_transmute- Severity
- warn
The dbg! macro is intended as a debugging tool. It should not be present in released software or committed to a version control system. Clippy puts this lint in the restriction group, at the level allow.
- Code
dbg_macro- Severity
- allow
- Since
- 1.34.0
In release builds debug_assert! macros are optimized out by the compiler. Therefore mutating something in a debug_assert! macro results in different behavior between a release and debug build. Clippy puts this lint in the nursery group, at the level allow.
- Code
debug_assert_with_mut_call- Severity
- allow
- Since
- 1.40.0
Using decimal literals for bit masks can make the code less readable and obscure the intended bit pattern. Binary, hexadecimal, or octal literals make the bit pattern more explicit and easier to understand at a glance. Clippy puts this lint in the pedantic group, at the level allow.
- Code
decimal_bitwise_operands- Severity
- allow
- Since
- 1.94.0
Especially for big powers of 2, a hexadecimal representation is usually more readable than a decimal representation. Clippy puts this lint in the restriction group, at the level allow.
- Code
decimal_literal_representation- Severity
- allow
Named constants are copied at every use site which means any change to their value will be lost after the newly created value is dropped. e.g. Clippy puts this lint in the suspicious group, at the level warn.
- Code
declare_interior_mutable_const- Severity
- warn
This adds code complexity and an unnecessary function call. Clippy puts this lint in the complexity group, at the level warn.
- Code
default_constructed_unit_structs- Severity
- warn
- Since
- 1.71.0
std::iter::empty() is the more idiomatic way. Clippy puts this lint in the style group, at the level warn.
- Code
default_instead_of_iter_empty- Severity
- warn
- Since
- 1.64.0
To ensure that every numeric type is chosen explicitly rather than implicitly. Clippy puts this lint in the restriction group, at the level allow.
- Code
default_numeric_fallback- Severity
- allow
- Since
- 1.52.0
It’s easier for the reader if the name of the type is used, rather than the generic Default. Clippy puts this lint in the pedantic group, at the level allow.
- Code
default_trait_access- Severity
- allow
Unions in Rust have unspecified layout by default, despite many people thinking that they lay out each field at the start of the union (like C does). That is, there are no guarantees about the offset of the fields for unions with multiple non-ZST fields without an explicitly specified layout. These cases may lead to undefined behavior in unsafe blocks. Clippy puts this lint in the restriction group, at the level allow.
- Code
default_union_representation- Severity
- allow
- Since
- 1.60.0
mod.rs is well-suited to acting as a table of contents — listing submodules and re-exports while leaving definitions to named files. Naming each file after its primary definition keeps filenames descriptive and unique, makes editor tabs and search results easier to scan, and makes the filesystem tree mirror the module tree, so the file layout is uniquely determined by the module structure. Clippy puts this lint in the restriction group, at the level allow.
- Code
definition_in_module_root- Severity
- allow
- Since
- 1.99.0
Since tool_attributes (rust-lang/rust#44690) are stable now, they should be used instead of the old cfg_attr(rustfmt) attributes. Clippy puts this lint in the complexity group, at the level warn.
- Code
deprecated_cfg_attr- Severity
- warn
- Since
- 1.32.0
This feature has been deprecated for years and shouldn’t be used anymore. Clippy puts this lint in the suspicious group, at the level warn.
- Code
deprecated_clippy_cfg_attr- Severity
- warn
- Since
- 1.78.0
Also allows “TBD” to signal future deprecation. For checking the version of the deprecation, it must be a valid semver. Failing that, the contained information is useless. Clippy puts this lint in the correctness group, at the level deny.
- Code
deprecated_semver- Severity
- deny
Immediately dereferencing a reference is no-op and makes the code less clear. Clippy puts this lint in the complexity group, at the level warn.
- Code
deref_addrof- Severity
- warn
Some people may prefer to dereference rather than slice. Clippy puts this lint in the restriction group, at the level allow.
- Code
deref_by_slicing- Severity
- allow
- Since
- 1.61.0
It is less concise. Clippy puts this lint in the complexity group, at the level warn.
- Code
derivable_impls- Severity
- warn
- Since
- 1.57.0
The implementation of these traits must agree (for example for use with sort) so it’s probably a bad idea to use a default-generated Ord implementation with an explicitly defined PartialOrd. In particular, the following must hold for any type implementing Ord: Clippy puts this lint in the correctness group, at the level deny.
- Code
derive_ord_xor_partial_ord- Severity
- deny
- Since
- 1.47.0
If a type T derives PartialEq and all of its members implement Eq, then T can always implement Eq. Implementing Eq allows T to be used in APIs that require Eq types. It also allows structs containing T to derive Eq themselves. Clippy puts this lint in the nursery group, at the level allow.
- Code
derive_partial_eq_without_eq- Severity
- allow
- Since
- 1.63.0
The implementation of these traits must agree (for example for use with HashMap) so it’s probably a bad idea to use a default-generated Hash implementation with an explicitly defined PartialEq. In particular, the following must hold for any type: Clippy puts this lint in the correctness group, at the level deny.
- Code
derived_hash_with_manual_eq- Severity
- deny
Some fields are undesirable in certain contexts, and it’s beneficial to lint for them as needed. Clippy puts this lint in the style group, at the level warn.
- Code
disallowed_fields- Severity
- warn
- Since
- 1.95.0
Some macros are undesirable in certain contexts, and it’s beneficial to lint for them as needed. Clippy puts this lint in the style group, at the level warn.
- Code
disallowed_macros- Severity
- warn
- Since
- 1.66.0
Some methods are undesirable in certain contexts, and it’s beneficial to lint for them as needed. Clippy puts this lint in the style group, at the level warn.
- Code
disallowed_methods- Severity
- warn
- Since
- 1.49.0
These names are usually placeholder names and should be avoided. Clippy puts this lint in the style group, at the level warn.
- Code
disallowed_names- Severity
- warn
It may be not desired to have many different scripts for identifiers in the codebase. Clippy puts this lint in the restriction group, at the level allow.
- Code
disallowed_script_idents- Severity
- allow
- Since
- 1.55.0
Some types are undesirable in certain contexts. Clippy puts this lint in the style group, at the level warn.
- Code
disallowed_types- Severity
- warn
- Since
- 1.55.0
It is often confusing to read. In addition, the sub-expression evaluation order for Rust is not well documented. Clippy puts this lint in the complexity group, at the level warn.
- Code
diverging_sub_expression- Severity
- warn
Because documentation generated by rustdoc will be broken since expected links won’t be links and just text. Clippy puts this lint in the pedantic group, at the level allow.
- Code
doc_broken_link- Severity
- allow
- Since
- 1.90.0
These files are not useful for compilation but will still be included. Also, if any of these non-source code file is updated, it will trigger a recompilation. Clippy puts this lint in the restriction group, at the level allow.
- Code
doc_include_without_cfg- Severity
- allow
- Since
- 1.85.0
The specification calls this a “lazy paragraph continuation.” This is easy to write but hard to read. Lazy continuations makes unintended markers hard to see, and make it harder to deduce the document’s intended structure. Clippy puts this lint in the style group, at the level warn.
- Code
doc_lazy_continuation- Severity
- warn
- Since
- 1.80.0
It can be written more simply using HTML-style <code> tags. Clippy puts this lint in the nursery group, at the level allow.
- Code
doc_link_code- Severity
- allow
- Since
- 1.87.0
It is likely a typo when defining an intra-doc link Clippy puts this lint in the pedantic group, at the level allow.
- Code
doc_link_with_quotes- Severity
- allow
- Since
- 1.63.0
Rustdoc supports markdown formatting, _, :: and camel-case probably indicates some code which should be included between ticks. _ can also be used for emphasis in markdown, this lint tries to consider that. Clippy puts this lint in the pedantic group, at the level allow.
- Code
doc_markdown- Severity
- allow
This is probably intended as an intra-doc link. If it is really supposed to be a reference definition, it can be written outside of the list item or quote. Clippy puts this lint in the suspicious group, at the level warn.
- Code
doc_nested_refdefs- Severity
- warn
- Since
- 1.85.0
Overindented list items in doc comments can lead to inconsistent and poorly formatted documentation when rendered. Excessive indentation may cause the text to be misinterpreted as a nested list item or code block, affecting readability and the overall structure of the documentation. Clippy puts this lint in the style group, at the level warn.
- Code
doc_overindented_list_items- Severity
- warn
- Since
- 1.86.0
Various Markdowns constructs are taken into account to avoid false positives. A project may wish to enforce consistent doc comments by making sure paragraphs end with a punctuation mark. Clippy puts this lint in the restriction group, at the level allow.
- Code
doc_paragraphs_missing_punctuation- Severity
- allow
- Since
- 1.93.0
Readability. Clippy puts this lint in the complexity group, at the level warn.
- Code
double_comparisons- Severity
- warn
Iterator::last is implemented by consuming the iterator, which is unnecessary if the iterator is a DoubleEndedIterator. Since Rust traits do not allow specialization, Iterator::last cannot be optimized for DoubleEndedIterator. Clippy puts this lint in the perf group, at the level warn.
- Code
double_ended_iterator_last- Severity
- warn
- Since
- 1.86.0
The attribute isn’t needed. Not using the result will already be reported. Alternatively, one can add some text to the attribute to improve the lint message. Clippy puts this lint in the style group, at the level warn.
- Code
double_must_use- Severity
- warn
- Since
- 1.40.0
This makes code harder to read and might indicate a mistake. Clippy puts this lint in the complexity group, at the level warn.
- Code
double_parens- Severity
- warn
Using mem::take is faster as it avoids the allocation. When using mem::take, the old collection is replaced with an empty one and ownership of the old collection is returned. Clippy puts this lint in the perf group, at the level warn.
- Code
drain_collect- Severity
- warn
- Since
- 1.72.0
Calling std::mem::drop is no different than dropping such a type. A different value may have been intended. Clippy puts this lint in the suspicious group, at the level warn.
- Code
drop_non_drop- Severity
- warn
- Since
- 1.62.0
Loading a file as a module more than once causes it to be compiled multiple times, taking longer and putting duplicate content into the module tree. Clippy puts this lint in the suspicious group, at the level warn.
- Code
duplicate_mod- Severity
- warn
- Since
- 1.63.0
It affects code readability. Clippy puts this lint in the style group, at the level warn.
- Code
duplicate_underscore_argument- Severity
- warn
Repeating an attribute on the same item (or globally on the same crate) is unnecessary and doesn’t have an effect. Clippy puts this lint in the suspicious group, at the level warn.
- Code
duplicated_attributes- Severity
- warn
- Since
- 1.79.0
Using a smaller unit for a duration that is evenly divisible by a larger unit reduces readability. Readers have to mentally convert values, which can be error-prone and makes the code less clear. Clippy puts this lint in the pedantic group, at the level allow.
- Code
duration_suboptimal_units- Severity
- allow
- Since
- 1.95.0
It’s more concise to call Duration::subsec_micros() or Duration::subsec_millis() than to calculate them. Clippy puts this lint in the complexity group, at the level warn.
- Code
duration_subsec- Severity
- warn
Eager evaluation means that the transmute call is executed regardless of whether the condition is true or false. This can introduce unsoundness and other subtle bugs. Clippy puts this lint in the correctness group, at the level deny.
- Code
eager_transmute- Severity
- deny
- Since
- 1.77.0
The additional lifetimes can make the code look more complicated. Clippy puts this lint in the pedantic group, at the level allow.
- Code
elidable_lifetime_names- Severity
- allow
- Since
- 1.87.0
Some coding guidelines require this (e.g., MISRA-C:2004 Rule 14.10). Clippy puts this lint in the restriction group, at the level allow.
- Code
else_if_without_else- Severity
- allow
Empty docs clutter code without adding value, reducing readability and maintainability. Clippy puts this lint in the suspicious group, at the level warn.
- Code
empty_docs- Severity
- warn
- Since
- 1.78.0
Empty Drop implementations have no effect when dropping an instance of the type. They are most likely useless. However, an empty Drop implementation prevents a type from being destructured, which might be the intention behind adding the implementation as a marker. Clippy puts this lint in the restriction group, at the level allow.
- Code
empty_drop- Severity
- allow
- Since
- 1.62.0
Empty brackets after a enum variant declaration are redundant and can be omitted, and it may be desirable to do so consistently for style. Clippy puts this lint in the restriction group, at the level allow.
- Code
empty_enum_variants_with_brackets- Severity
- allow
- Since
- 1.77.0
If you only want a type which can’t be instantiated, you should use ! (the primitive type “never”), because ! has more extensive compiler support (type inference, etc.) and implementations of common traits. Clippy puts this lint in the nursery group, at the level allow.
- Code
empty_enums- Severity
- allow
The attribute may have meant to be an inner attribute (#![attr]). If it was meant to be an outer attribute (#[attr]) then the empty line should be removed Clippy puts this lint in the suspicious group, at the level warn.
- Code
empty_line_after_outer_attr- Severity
- warn
These busy loops burn CPU cycles without doing anything. It is almost always a better idea to panic! than to have a busy loop. Clippy puts this lint in the suspicious group, at the level warn.
- Code
empty_loop- Severity
- warn
Empty brackets after a struct declaration can be omitted, and it may be desirable to do so consistently for style. Clippy puts this lint in the restriction group, at the level allow.
- Code
empty_structs_with_brackets- Severity
- allow
- Since
- 1.62.0
This will truncate the variant value on 32 bit architectures, but works fine on 64 bit. Clippy puts this lint in the correctness group, at the level deny.
- Code
enum_clike_unportable_variant- Severity
- deny
It is usually better style to use the prefixed name of an enumeration variant, rather than importing variants. Clippy puts this lint in the pedantic group, at the level allow.
- Code
enum_glob_use- Severity
- allow
Enumeration variant names should specify their variant, not repeat the enumeration name. Clippy puts this lint in the style group, at the level warn.
- Code
enum_variant_names- Severity
- warn
This is usually just a typo or a copy and paste error. Clippy puts this lint in the correctness group, at the level deny.
- Code
eq_op- Severity
- deny
Clippy puts this lint in the nursery group, at the level allow.
- Code
equatable_if_let- Severity
- allow
- Since
- 1.57.0
The whole expression can be replaced by zero. This is most likely not the intended outcome and should probably be corrected Clippy puts this lint in the correctness group, at the level deny.
- Code
erasing_op- Severity
- deny
.expect_err() can be called directly to avoid the extra type conversion from err(). Clippy puts this lint in the style group, at the level warn.
- Code
err_expect- Severity
- warn
- Since
- 1.62.0
It can become confusing when a codebase has 20 types all named Error, requiring either aliasing them in the use statement or qualifying them like my_module::Error. This hinders comprehension, as it requires you to memorize every variation of importing Error used across a codebase. Clippy puts this lint in the restriction group, at the level allow.
- Code
error_impl_error- Severity
- allow
- Since
- 1.73.0
It can severely hinder readability. Clippy puts this lint in the complexity group, at the level warn.
- Code
excessive_nesting- Severity
- warn
- Since
- 1.72.0
Rust will truncate the literal silently. Clippy puts this lint in the style group, at the level warn.
- Code
excessive_precision- Severity
- warn
Making an enum exhaustive is a stability commitment: adding a variant is a breaking change. A project may wish to ensure that there are no exhaustive enums or that every exhaustive enum is explicitly #[allow]ed. Clippy puts this lint in the restriction group, at the level allow.
- Code
exhaustive_enums- Severity
- allow
- Since
- 1.51.0
Making a struct exhaustive is a stability commitment: adding a field is a breaking change. A project may wish to ensure that there are no exhaustive structs or that every exhaustive struct is explicitly #[allow]ed. Clippy puts this lint in the restriction group, at the level allow.
- Code
exhaustive_structs- Severity
- allow
- Since
- 1.51.0
Calls to exit() immediately terminate the program. exit() immediately terminates the program with no information other than an exit code. This provides no means to troubleshoot a problem, and may be an unexpected side effect. Clippy puts this lint in the restriction group, at the level allow.
- Code
exit- Severity
- allow
- Since
- 1.41.0
The function will always be called. Clippy puts this lint in the perf group, at the level warn.
- Code
expect_fun_call- Severity
- warn
Usually it is better to handle the None or Err case. Still, for a lot of quick-and-dirty code, expect is a good choice, which is why this lint is Allow by default. Clippy puts this lint in the restriction group, at the level allow.
- Code
expect_used- Severity
- allow
- Since
- 1.45.0
To avoid surprising behavior, these traits should agree and the behavior of Copy cannot be overridden. In almost all situations a Copy type should have a Clone implementation that does nothing more than copy the object, which is what #[derive(Copy, Clone)] gets you. Clippy puts this lint in the pedantic group, at the level allow.
- Code
expl_impl_clone_on_copy- Severity
- allow
This unnecessarily complicates the code. Clippy puts this lint in the complexity group, at the level warn.
- Code
explicit_auto_deref- Severity
- warn
- Since
- 1.64.0
Using .enumerate() makes the intent more clear, declutters the code and may be faster in some instances. Clippy puts this lint in the complexity group, at the level warn.
- Code
explicit_counter_loop- Severity
- warn
Dereferencing by &*x or &mut *x is clearer and more concise, when not part of a method chain. Clippy puts this lint in the pedantic group, at the level allow.
- Code
explicit_deref_methods- Severity
- allow
- Since
- 1.44.0
Readability. Clippy puts this lint in the pedantic group, at the level allow.
- Code
explicit_into_iter_loop- Severity
- allow
Readability. Clippy puts this lint in the pedantic group, at the level allow.
- Code
explicit_iter_loop- Severity
- allow
Using (e)println! is clearer and more concise Clippy puts this lint in the complexity group, at the level warn.
- Code
explicit_write- Severity
- warn
Nothing. extend_from_slice
This lint has been deprecated Clippy puts this lint in the deprecated group, at the level none.
- Code
extend_from_slice- Severity
- none
Using append instead of extend is more concise and faster Clippy puts this lint in the perf group, at the level warn.
- Code
extend_with_drain- Severity
- warn
- Since
- 1.55.0
TryFrom should be used if there’s a possibility of failure. Clippy puts this lint in the nursery group, at the level allow.
- Code
fallible_impl_from- Severity
- allow
It’s more idiomatic to use the functional update syntax. Clippy puts this lint in the style group, at the level warn.
- Code
field_reassign_with_default- Severity
- warn
- Since
- 1.49.0
These make a field visible within a scope between public and private. Scoped visibility modifiers cause a field to be accessible within some scope between public and private, potentially within an entire crate. This allows for fields to be non-private while upholding internal invariants, but can be a code smell. Scoped visibility requires checking a greater area, potentially an entire crate, to verify that an invariant is upheld, and global analysis requires a lot of effort. Clippy puts this lint in the restriction group, at the level allow.
- Code
field_scoped_visibility_modifiers- Severity
- allow
- Since
- 1.81.0
When people testing a file type with FileType::is_file they are testing whether a path is something they can get bytes from. But is_file doesn’t cover special file types in unix-like systems, and doesn’t cover symlink in windows. Using !FileType::is_dir() is a better way to that intention. Clippy puts this lint in the restriction group, at the level allow.
- Code
filetype_is_file- Severity
- allow
- Since
- 1.42.0
This can be written with filter then map instead, which would reduce nesting and separates the filtering from the transformation phase. This comes with no cost to performance and is just cleaner. Clippy puts this lint in the style group, at the level warn.
- Code
filter_map_bool_then- Severity
- warn
- Since
- 1.73.0
Readability, this can be written more concisely by using flatten. Clippy puts this lint in the complexity group, at the level warn.
- Code
filter_map_identity- Severity
- warn
- Since
- 1.52.0
Readability, this can be written more concisely as _.find_map(_). Clippy puts this lint in the pedantic group, at the level allow.
- Code
filter_map_next- Severity
- allow
- Since
- 1.36.0
Readability, this can be written more concisely as _.find(_). Clippy puts this lint in the complexity group, at the level warn.
- Code
filter_next- Severity
- warn
Readability, this can be written more concisely by using flatten. Clippy puts this lint in the complexity group, at the level warn.
- Code
flat_map_identity- Severity
- warn
- Since
- 1.39.0
filter_map() is known to always produce 0 or 1 output items per input item, rather than however many the inner iterator type produces. Therefore, it maintains the upper bound in Iterator::size_hint(), and communicates to the reader that the input items are not being expanded into multiple output items without their having to notice that the mapping function returns an Option. Clippy puts this lint in the pedantic group, at the level allow.
- Code
flat_map_option- Severity
- allow
- Since
- 1.53.0
For some embedded systems or kernel development, it can be useful to rule out floating-point numbers. Clippy puts this lint in the restriction group, at the level allow.
- Code
float_arithmetic- Severity
- allow
Floating point calculations are usually imprecise, so asking if two values are exactly equal is asking for trouble because arriving at the same logical result via different routes (e.g. calculation versus constant) may yield different values. Clippy puts this lint in the pedantic group, at the level allow.
- Code
float_cmp- Severity
- allow
Floating point calculations are usually imprecise, so asking if two values are exactly equal is asking for trouble because arriving at the same logical result via different routes (e.g. calculation versus constant) may yield different values. Clippy puts this lint in the restriction group, at the level allow.
- Code
float_cmp_const- Severity
- allow
Note the missing .abs(). The code without .abs() is more likely to have a bug. Clippy puts this lint in the suspicious group, at the level warn.
- Code
float_equality_without_abs- Severity
- warn
- Since
- 1.48.0
Boolean parameters obscure meaning at the call site. The reader has to remember what each true or false means and which position each flag belongs in, with no help from the type system. Clippy puts this lint in the pedantic group, at the level allow.
- Code
fn_params_excessive_bools- Severity
- allow
- Since
- 1.43.0
Casting a function pointer to anything other than usize/isize is not portable across architectures. If the target type is too small the address would be truncated, and target types larger than usize are unnecessary. Clippy puts this lint in the style group, at the level warn.
- Code
fn_to_numeric_cast- Severity
- warn
Casting a function pointer to an integer can have surprising results and can occur accidentally if parentheses are omitted from a function call. If you aren’t doing anything low-level with function pointers then you can opt out of casting functions to integers in order to avoid mistakes. Alternatively, you can use this lint to audit all uses of function pointer casts in your code. Clippy puts this lint in the restriction group, at the level allow.
- Code
fn_to_numeric_cast_any- Severity
- allow
- Since
- 1.58.0
Such a cast discards some bits of the function’s address. If this is intended, it would be more clearly expressed by casting to usize first, then casting the usize to the intended type (with a comment) to perform the truncation. Clippy puts this lint in the style group, at the level warn.
- Code
fn_to_numeric_cast_with_truncation- Severity
- warn
Readability. There are keys and values methods that can be used to express that don’t need the values or keys. Clippy puts this lint in the style group, at the level warn.
- Code
for_kv_map- Severity
- warn
Using a unbounded range over char and integers will unexpectedly not handle overflows so it will lead to panics or infinite loops. Clippy puts this lint in the suspicious group, at the level warn.
- Code
for_unbounded_range- Severity
- warn
- Since
- 1.98.0
Calling std::mem::forget is no different than dropping such a type. A different value may have been intended. Clippy puts this lint in the suspicious group, at the level warn.
- Code
forget_non_drop- Severity
- warn
- Since
- 1.62.0
This allocates a new string for every element in the iterator. This can be done more efficiently by creating the String once and appending to it in Iterator::fold, using either the write! macro which supports exactly the same syntax as the format! macro, or concatenating with + in case the iterator yields &str/String. Clippy puts this lint in the pedantic group, at the level allow.
- Code
format_collect- Severity
- allow
- Since
- 1.73.0
Suggests inlining the format! call. The recommended code is both shorter and avoids a temporary allocation. Clippy puts this lint in the perf group, at the level warn.
- Code
format_in_format_args- Severity
- warn
- Since
- 1.58.0
Introduces an extra, avoidable heap allocation. Clippy puts this lint in the pedantic group, at the level allow.
- Code
format_push_string- Severity
- allow
- Since
- 1.62.0
This is (probably) a typo, and results in it not being a doc comment; just a regular comment. Clippy puts this lint in the suspicious group, at the level warn.
- Code
four_forward_slashes- Severity
- warn
- Since
- 1.73.0