Programming Search⌘K

Rust lints, page 1 of 5

The lint rules of Rust, with what each one finds. This page has 844 cards.

Checks for comparisons where one side of the relation is either the minimum or maximum value for its type and warns if it involves a case that is always true or always false. absurd_extreme_comparisons

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Finds items imported through alloc when available through core. alloc_instead_of_core

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for usage of the #[allow] attribute and suggests replacing it with the #[expect] attribute (See RFC 2383) allow_attributes

#[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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for floating point literals that approximate constants which are defined in std::f32::consts or std::f64::consts, respectively, suggesting to use the predefined constant. approx_constant

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Confirms that items are sorted in source files as per configuration. arbitrary_source_item_ordering

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks any kind of arithmetic operation of any type. arithmetic_side_effects

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for usage of as conversions. as_conversions

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for warn/deny/forbid attributes targeting the whole clippy::restriction category. blanket_clippy_restriction_lints

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Warns when a match, if let, or while let scrutinee is wrapped in a block. block_scrutinee

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for the usage of &expr as *const T or &mut expr as *mut T, and suggest using &raw const or &raw mut instead. borrow_as_ptr

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for usage of &Box<T> anywhere in the code. borrowed_box

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for usage of Box<T> where T is a collection such as Vec anywhere in the code. box_collection

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks to see if all common metadata is defined in Cargo.toml. cargo_common_metadata

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for casts between numeric types that can be replaced by safe conversion functions. cast_lossless

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for casts between numeric types that may truncate large values. cast_possible_truncation

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for casts from an unsigned type to a signed type of the same size, or possibly smaller due to target-dependent integers. cast_possible_wrap

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for casts from any numeric type to a float type where the receiving type cannot store all values from the original type without rounding errors. cast_precision_loss

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for casts from a signed to an unsigned numeric type. cast_sign_loss

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for as casts between raw pointers to slices with differently sized elements. cast_slice_different_sizes

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for usage of a character position yielded by .chars().enumerate() in a context where a byte index is expected, such as an argument to a specific str method or indexing into a str or String. char_indices_as_byte_indices

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for expressions where a character literal is cast to u8 and suggests using a byte literal instead. char_lit_as_u8

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for usage of .clone() on a ref-counted pointer, (Rc, Arc, rc::Weak, or sync::Weak), and suggests calling Clone via unified function syntax instead (e.g., Rc::clone(foo)). clone_on_ref_ptr

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Protects against unintended coercion of references to container types to &dyn Any when the container type dereferences to a dyn Any which could be directly referenced instead. coerce_container_to_any

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for collections that are never queried. collection_is_never_read

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for comparing to an empty slice such as "" or [], and suggests using .is_empty() where applicable. comparison_to_empty

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for casts of a primitive method pointer like max/min to any integer type. confusing_method_to_numeric_cast

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks usage of std::fs::create_dir and suggest using std::fs::create_dir_all instead. create_dir

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for function/method calls with a mutable parameter in debug_assert!, debug_assert_eq! and debug_assert_ne! macros. debug_assert_with_mut_call

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for decimal literals used as bit masks in bitwise operations. decimal_bitwise_operands

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Displays a warning when a union is declared with the default representation (without a #[repr(C)] attribute). default_union_representation

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for definitions (structs, functions, traits, etc.) in mod.rs files. lib.rs and main.rs are not checked. definition_in_module_root

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Lints against manual PartialOrd and Ord implementations for types with a derived Ord or PartialOrd implementation. derive_ord_xor_partial_ord

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for types that derive PartialEq and could implement Eq. derive_partial_eq_without_eq

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Lints against manual PartialEq implementations for types with a derived Hash implementation. derived_hash_with_manual_eq

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Detects doc comments that use double spaces as hard line break, instead of backslash (\). doc_comment_double_space_linebreaks

Double spaces, when used as hard line break in doc comments, can be difficult to see, and may accidentally be removed during automatic formatting or manual refactoring. The use of a backslash (\) is clearer in this regard. Clippy puts this lint in the pedantic group, at the level allow.

Code
doc_comment_double_space_linebreaks
Severity
allow
Since
1.87.0

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

In CommonMark Markdown, the language used to write doc comments, a paragraph nested within a list or block quote does not need any line after the first one to be indented or marked. doc_lazy_continuation

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Detects overindented list items in doc comments where the continuation lines are indented more than necessary. doc_overindented_list_items

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for doc comments whose paragraphs do not end with a period or another punctuation mark. doc_paragraphs_missing_punctuation

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for Iterator::last being called on a DoubleEndedIterator, which can be replaced with DoubleEndedIterator::next_back. double_ended_iterator_last

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for a #[must_use] attribute without further information on functions and methods that return a type already considered as #[must_use]. double_must_use

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for instances where a std::time::Duration is constructed using a smaller time unit when the value could be expressed more clearly using a larger unit. duration_suboptimal_units

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for integer validity checks, followed by a transmute that is (incorrectly) evaluated eagerly (e.g. using bool::then_some). eager_transmute

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for empty Drop implementations. empty_drop

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for enums with no variants, which therefore are uninhabited types (cannot be instantiated). empty_enums

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for empty lines after doc comments. empty_line_after_doc_comments

The doc comment may have meant to be an inner doc comment, regular comment or applied to some old code that is now commented out. If it was intended to be a doc comment, then the empty line should be removed. Clippy puts this lint in the suspicious group, at the level warn.

Code
empty_line_after_doc_comments
Severity
warn
Since
1.70.0

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for types named Error that implement Error. error_impl_error

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Warns on any exported structs that are not tagged #[non_exhaustive] exhaustive_structs

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for explicit Clone implementations for Copy types. expl_impl_clone_on_copy

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for usage of scoped visibility modifiers, like pub(crate), on fields. field_scoped_visibility_modifiers

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for FileType::is_file(). filetype_is_file

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for usage of Iterator::flat_map() where filter_map() could be used instead. flat_map_option

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for (in-)equality comparisons on floating-point values (apart from zero), except in functions called *eq* (which probably implement equality for a type involving floats). float_cmp

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for (in-)equality comparisons on constant floating-point values (apart from zero), except in functions called *eq* (which probably implement equality for a type involving floats). float_cmp_const

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for casts of a function pointer to any integer type. fn_to_numeric_cast_any

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for casts of a function pointer to a numeric type not wide enough to store an address. fn_to_numeric_cast_with_truncation

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.

Checks for usage of .map(|_| format!(..)).collect::<String>(). format_collect

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

Source: rust-lang.github.io. JSON record. This entry is a card. Help write this page.