Using the default name for parameters of a trait method is more consistent. Clippy puts this lint in the restriction group, at the level allow.
- Code
renamed_function_params- Severity
- allow
- Since
- 1.80.0
For example, String.repeat(1) is equivalent to .clone(). If cloning the string is the intention behind this, clone() should be used. Clippy puts this lint in the complexity group, at the level warn.
- Code
repeat_once- Severity
- warn
- Since
- 1.47.0
These constructs work by cloning the element, but cloning a Vec<_> does not respect the old vector’s capacity and effectively discards it. Clippy puts this lint in the suspicious group, at the level warn.
- Code
repeat_vec_with_capacity- Severity
- warn
- Since
- 1.76.0
This incurs an extra heap allocation compared to assigning the boxed storage. Clippy puts this lint in the perf group, at the level warn.
- Code
replace_box- Severity
- warn
- Since
- 1.92.0
This lint has been deprecated Clippy puts this lint in the deprecated group, at the level none.
- Code
replace_consts- Severity
- none
- Since
- 1.44.0
Without qualification, repr(packed) implies repr(Rust). The Rust-ABI is inherently unstable. While this is fine as long as the type is accessed correctly within Rust-code, most uses of #[repr(packed)] involve FFI and/or data structures specified by network-protocols or other external specifications. In such situations, the unstable Rust-ABI implied in #[repr(packed)] may lead to future bugs should the Rust-ABI change. Clippy puts this lint in the suspicious group, at the level warn.
- Code
repr_packed_without_abi- Severity
- warn
- Since
- 1.85.0
The Vec::with_capacity constructor is less complex. Clippy puts this lint in the complexity group, at the level warn.
- Code
reserve_after_initialization- Severity
- warn
- Since
- 1.74.0
Correctness and readability. It’s like having a wildcard pattern after matching all enum variants explicitly. Clippy puts this lint in the restriction group, at the level allow.
- Code
rest_pat_in_fully_bound_structs- Severity
- allow
- Since
- 1.43.0
It might lead to unhandled fields when the struct changes. Clippy puts this lint in the restriction group, at the level allow.
- Code
rest_pattern_accessible_field- Severity
- allow
- Since
- 1.99.0
Result implements IntoIterator<Item = T>. This means that Result can be flattened automatically without suspicious-looking unwrap calls. Clippy puts this lint in the complexity group, at the level warn.
- Code
result_filter_map- Severity
- warn
- Since
- 1.77.0
A Result is at least as large as the Err-variant. While we expect that variant to be seldom used, the compiler needs to reserve and move that much memory every single time. Furthermore, errors are often simply passed up the call-stack, making use of the ?-operator and its type-conversion mechanics. If the Err-variant further up the call-stack stores the Err-variant in question (as library code often does), it itself needs to be at least as large, propagating the problem. Clippy puts this lint in the perf group, at the level warn.
- Code
result_large_err- Severity
- warn
- Since
- 1.65.0
Readability, this can be written more concisely as _.ok(). Clippy puts this lint in the style group, at the level warn.
- Code
result_map_or_into_option- Severity
- warn
- Since
- 1.44.0
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
result_map_unit_fn- Severity
- warn
It suggests using a custom type that implements std::error::Error. Unit does not implement Error and carries no further information about what went wrong. Clippy puts this lint in the style group, at the level warn.
- Code
result_unit_err- Severity
- warn
- Since
- 1.49.0
The and_then method is used to chain a computation that returns an Option or a Result. This can be replaced with the ? operator, which is more concise and idiomatic. Clippy puts this lint in the restriction group, at the level allow.
- Code
return_and_then- Severity
- allow
- Since
- 1.86.0
Methods returning Self often create new values, having the #[must_use] attribute prevents users from “forgetting” to use the newly created value. Clippy puts this lint in the pedantic group, at the level allow.
- Code
return_self_not_must_use- Severity
- allow
- Since
- 1.59.0
Also triggers if x is equal to y when they are conditions to a for loop. Empty ranges yield no values so iterating them is a no-op. Moreover, trying to use a reversed range to index a slice will panic at run-time. Clippy puts this lint in the correctness group, at the level deny.
- Code
reversed_empty_ranges- Severity
- deny
- Since
- 1.45.0
This is probably a copy & paste error. Despite the fact that function can have side effects and if works as intended, such an approach is implicit and can be considered a “code smell”. Clippy puts this lint in the pedantic group, at the level allow.
- Code
same_functions_in_if_condition- Severity
- allow
- Since
- 1.41.0
This kind of operation can be expressed more succinctly with vec![item; SIZE] or vec.resize(NEW_SIZE, item) and using these alternatives may also have better performance. Clippy puts this lint in the style group, at the level warn.
- Code
same_item_push- Severity
- warn
- Since
- 1.47.0
If the same expression is being passed for the length and capacity, it is most likely a semantic error. In the case of a Vec, for example, the only way to end up with one that has the same length and capacity is by going through a boxed slice, e.g. Box::from(some_vec), which shrinks the capacity to match the length. Clippy puts this lint in the pedantic group, at the level allow.
- Code
same_length_and_capacity- Severity
- allow
- Since
- 1.94.0
Confusing. Clippy puts this lint in the restriction group, at the level allow.
- Code
same_name_method- Severity
- allow
- Since
- 1.57.0
Readability, this can be written more concisely as: Clippy puts this lint in the nursery group, at the level allow.
- Code
search_is_some- Severity
- allow
Readability. Use dedicated method. Clippy puts this lint in the complexity group, at the level warn.
- Code
seek_from_current- Severity
- warn
- Since
- 1.67.0
Readability. There is a specific method that was implemented for this exact scenario. Clippy puts this lint in the complexity group, at the level warn.
- Code
seek_to_start_instead_of_rewind- Severity
- warn
- Since
- 1.67.0
Self-assignments are redundant and unlikely to be intentional. Clippy puts this lint in the correctness group, at the level deny.
- Code
self_assignment- Severity
- deny
- Since
- 1.48.0
Repeating the name of the type is redundant. Clippy puts this lint in the style group, at the level warn.
- Code
self_named_constructors- Severity
- warn
- Since
- 1.55.0
Having multiple module layout styles in a project can be confusing. Clippy puts this lint in the restriction group, at the level allow.
- Code
self_named_module_files- Severity
- allow
- Since
- 1.57.0
It may be possible to remove the self argument, allowing the function to be used without an object of type Self. Clippy puts this lint in the pedantic group, at the level allow.
- Code
self_only_used_in_recursion- Severity
- allow
- Since
- 1.92.0
The semicolon might be optional but when extending the block with new code, it doesn’t require a change in previous last line. Clippy puts this lint in the pedantic group, at the level allow.
- Code
semicolon_if_nothing_returned- Severity
- allow
- Since
- 1.52.0
For consistency it’s best to have the semicolon inside/outside the block. Either way is fine and this lint suggests inside the block. Take a look at semicolon_outside_block for the other alternative. Clippy puts this lint in the restriction group, at the level allow.
- Code
semicolon_inside_block- Severity
- allow
- Since
- 1.68.0
For consistency it’s best to have the semicolon inside/outside the block. Either way is fine and this lint suggests outside the block. Take a look at semicolon_inside_block for the other alternative. Clippy puts this lint in the restriction group, at the level allow.
- Code
semicolon_outside_block- Severity
- allow
- Since
- 1.68.0
To enforce separated literal suffix style, see the unseparated_literal_suffix lint. Suffix style should be consistent. Clippy puts this lint in the restriction group, at the level allow.
- Code
separated_literal_suffix- Severity
- allow
- Since
- 1.58.0
Serde is very finicky about how its API should be used, but the type system can’t be used to enforce it (yet?). Clippy puts this lint in the correctness group, at the level deny.
- Code
serde_api_misuse- Severity
- deny
Using just insert and checking the returned bool is more efficient. Clippy puts this lint in the nursery group, at the level allow.
- Code
set_contains_or_insert- Severity
- allow
- Since
- 1.81.0
Some argue that name shadowing like this hurts readability, because a value may be bound to different things depending on position in the code. Clippy puts this lint in the restriction group, at the level allow.
- Code
shadow_reuse- Severity
- allow
To require that what are formally distinct variables be given distinct names. Clippy puts this lint in the restriction group, at the level allow.
- Code
shadow_same- Severity
- allow
Shadowing a binding with a closely related one is part of idiomatic Rust, but shadowing a binding by accident with an unrelated one may indicate a mistake. Clippy puts this lint in the restriction group, at the level allow.
- Code
shadow_unrelated- Severity
- allow
Using a short circuit boolean condition as a statement may hide the fact that the second part is executed or not depending on the outcome of the first part. Clippy puts this lint in the complexity group, at the level warn.
- Code
short_circuit_statement- Severity
- warn
Nothing. should_assert_eq
This lint has been deprecated Clippy puts this lint in the deprecated group, at the level none.
- Code
should_assert_eq- Severity
- none
Implementing the traits improve ergonomics for users of the code, often with very little cost. Also people seeing a mul(...) method may expect * to work equally, so you should have good reason to disappoint them. Clippy puts this lint in the style group, at the level warn.
- Code
should_implement_trait- Severity
- warn
The expected panic message should be specified to ensure that the test is actually panicking with the expected message, and not another unrelated panic. Clippy puts this lint in the pedantic group, at the level allow.
- Code
should_panic_without_expect- Severity
- allow
- Since
- 1.74.0
The clippy::has_significant_drop attribute can be added to types whose Drop impls have an important side-effect, such as unlocking a mutex, making it important for users to be able to accurately understand their lifetimes. When a temporary is returned in a function call in a match scrutinee, its lifetime lasts until the end of the match block, which may be surprising. Clippy puts this lint in the nursery group, at the level allow.
- Code
significant_drop_in_scrutinee- Severity
- allow
- Since
- 1.60.0
In other words, enforces the “tightening” of their possible lifetimes. Elements marked with #[clippy::has_significant_drop] are generally synchronizing primitives that manage shared resources, as such, it is desired to release them as soon as possible to avoid unnecessary resource contention. Clippy puts this lint in the nursery group, at the level allow.
- Code
significant_drop_tightening- Severity
- allow
- Since
- 1.69.0
In particular, the lint checks for names with a single character change. It’s hard to distinguish between names that differ only by a single character. Clippy puts this lint in the pedantic group, at the level allow.
- Code
similar_names- Severity
- allow
Does not lint tests. If a function is only used once (perhaps because it used to be used more widely), then the code could be simplified by moving that function’s code into its caller. Clippy puts this lint in the restriction group, at the level allow.
- Code
single_call_fn- Severity
- allow
- Since
- 1.72.0
It’s less clear that we are pushing a single character. Clippy puts this lint in the style group, at the level warn.
- Code
single_char_add_str- Severity
- warn
- Since
- 1.49.0
A single character is likely not enough to express the purpose of a lifetime. Using a longer name can make code easier to understand. Clippy puts this lint in the restriction group, at the level allow.
- Code
single_char_lifetime_names- Severity
- allow
- Since
- 1.60.0
While this can make a perf difference on some systems, benchmarks have proven inconclusive. But at least using a char literal makes it clear that we are looking at a single character. Clippy puts this lint in the pedantic group, at the level allow.
- Code
single_char_pattern- Severity
- allow
Import with single component use path such as use cratename; is not necessary, and thus should be removed. Clippy puts this lint in the style group, at the level warn.
- Code
single_component_path_imports- Severity
- warn
- Since
- 1.43.0
There is no reason to have a loop of a single element. Clippy puts this lint in the complexity group, at the level warn.
- Code
single_element_loop- Severity
- warn
- Since
- 1.49.0
Just readability – if let nests less than a match. Clippy puts this lint in the style group, at the level warn.
- Code
single_match- Severity
- warn
Just readability – if let nests less than a match. Clippy puts this lint in the pedantic group, at the level allow.
- Code
single_match_else- Severity
- allow
Taking and returning an Option<T> may require additional Some(_) and unwrap if all you have is a T. Clippy puts this lint in the nursery group, at the level allow.
- Code
single_option_map- Severity
- allow
- Since
- 1.87.0
This is almost always incorrect, as it will result in a Vec that has only one element. Almost always, the programmer intended for it to include all elements in the range or for the end of the range to be the length instead. Clippy puts this lint in the suspicious group, at the level warn.
- Code
single_range_in_vec_init- Severity
- warn
- Since
- 1.72.0
These functions expect a count of T and not a number of bytes Clippy puts this lint in the correctness group, at the level deny.
- Code
size_of_in_element_count- Severity
- deny
- Since
- 1.50.0
Calling size_of_val() with a reference to a reference as the argument yields the size of the reference-type, not the size of the value behind the reference. Clippy puts this lint in the suspicious group, at the level warn.
- Code
size_of_ref- Severity
- warn
- Since
- 1.68.0
Readability, this can be written more concisely as _.find(!condition). Clippy puts this lint in the complexity group, at the level warn.
- Code
skip_while_next- Severity
- warn
- Since
- 1.42.0
It involves doing an unnecessary UTF-8 alignment check which is less efficient, and can cause a panic. Clippy puts this lint in the perf group, at the level warn.
- Code
sliced_string_as_bytes- Severity
- warn
- Since
- 1.86.0
These structures are non-idiomatic and less efficient than simply using vec![0; len]. Clippy puts this lint in the perf group, at the level warn.
- Code
slow_vector_initialization- Severity
- warn
- Since
- 1.32.0
Readability, this can be written more concisely as predicate.then_some(x). Clippy puts this lint in the complexity group, at the level warn.
- Code
some_filter- Severity
- warn
- Since
- 1.97.0
Typically, using a stable sort consumes more memory and cpu cycles. Because values which compare equal are identical, preserving their relative order (the guarantee that a stable sort provides) means nothing, while the extra costs still apply. Clippy puts this lint in the pedantic group, at the level allow.
- Code
stable_sort_primitive- Severity
- allow
- Since
- 1.47.0
Crates which have no_std compatibility and require alloc may wish to ensure types are imported from alloc to ensure disabling std 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
std_instead_of_alloc- Severity
- allow
- Since
- 1.64.0
Crates which have no_std compatibility may wish to ensure types are imported from core to ensure disabling std 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
std_instead_of_core- Severity
- allow
- Since
- 1.64.0
Hard-coding the line endings makes the code less compatible. str.lines should be used instead. Clippy puts this lint in the pedantic group, at the level allow.
- Code
str_split_at_newline- Severity
- allow
- Since
- 1.77.0
The to_string method is also used on other types to convert them to a string. When called on a &str it turns the &str into the owned variant String, which can be more specifically expressed with .to_owned(). Clippy puts this lint in the restriction group, at the level allow.
- Code
str_to_string- Severity
- allow
This particular Add implementation is asymmetric (the other operand need not be String, but x does), while addition as mathematically defined is symmetric, and the String::push_str(_) function is a perfectly good replacement. Therefore, some dislike it and wish not to have it in their code. Clippy puts this lint in the restriction group, at the level allow.
- Code
string_add- Severity
- allow
It’s not really bad, but some people think that the .push_str(_) method is more readable. Clippy puts this lint in the pedantic group, at the level allow.
- Code
string_add_assign- Severity
- allow
.push_str(s) is clearer Clippy puts this lint in the style group, at the level warn.
- Code
string_extend_chars- Severity
- warn
It’s unnecessary, the string can be used directly. Clippy puts this lint in the complexity group, at the level warn.
- Code
string_from_utf8_as_bytes- Severity
- warn
- Since
- 1.50.0
Byte string literals (e.g., b"foo") can be used instead. They are shorter but less discoverable than as_bytes(). Clippy puts this lint in the nursery group, at the level allow.
- Code
string_lit_as_bytes- Severity
- allow
It’s significantly slower than using a pattern instead, like matches!(c, '\\' | '.' | '+'). Clippy puts this lint in the restriction group, at the level allow.
- Code
string_lit_chars_any- Severity
- allow
- Since
- 1.73.0
UTF-8 characters span multiple bytes, and it is easy to inadvertently confuse character counts and string indices. This may lead to panics, and should warrant some test cases containing wide UTF-8 characters. This lint is most useful in code that should avoid panics at all costs. Clippy puts this lint in the restriction group, at the level allow.
- Code
string_slice- Severity
- allow
- Since
- 1.58.0
Nothing. string_to_string
This lint has been deprecated Clippy puts this lint in the deprecated group, at the level none.
- Code
string_to_string- Severity
- none
- Since
- 1.91.0
libc::strlen is an unsafe function, which we don’t need to call if all we want to know is the length of the c-string. Clippy puts this lint in the complexity group, at the level warn.
- Code
strlen_on_c_strings- Severity
- warn
- Since
- 1.55.0
Excessive bools in a struct is often a sign that the type is being used to represent a state machine, which is much better implemented as an enum. Clippy puts this lint in the pedantic group, at the level allow.
- Code
struct_excessive_bools- Severity
- allow
- Since
- 1.43.0
Information common to all struct fields is better represented in the struct name. Clippy puts this lint in the pedantic group, at the level allow.
- Code
struct_field_names- Severity
- allow
- Since
- 1.75.0
Negatively impacts accuracy and performance. Clippy puts this lint in the nursery group, at the level allow.
- Code
suboptimal_flops- Severity
- allow
- Since
- 1.43.0
This is probably a typo or copy-and-paste error and not intended. Clippy puts this lint in the suspicious group, at the level warn.
- Code
suspicious_arithmetic_impl- Severity
- warn
This is either a typo of *=, != or -= or confusing. Clippy puts this lint in the suspicious group, at the level warn.
- Code
suspicious_assignment_formatting- Severity
- warn
Command::arg() does not split arguments by space. An argument like arg("-t ext2") will be passed as a single argument to the command, which is likely not what was intended. Clippy puts this lint in the suspicious group, at the level warn.
- Code
suspicious_command_arg_space- Severity
- warn
- Since
- 1.69.0
It lints if the else is followed immediately by a newline or the else seems to be missing. 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
suspicious_else_formatting- Severity
- warn
It looks suspicious. Maybe map was confused with filter. If the map call is intentional, this should be rewritten using inspect. Or, if you intend to drive the iterator to completion, you can just use for_each instead. Clippy puts this lint in the suspicious group, at the level warn.
- Code
suspicious_map- Severity
- warn
- Since
- 1.39.0
This is probably a typo or copy-and-paste error and not intended. Clippy puts this lint in the suspicious group, at the level warn.
- Code
suspicious_op_assign_impl- Severity
- warn
create() alone will either create a new file or open an existing file. If the file already exists, it will be overwritten when written to, but the file will not be truncated by default. If less data is written to the file than it already contains, the remainder of the file will remain unchanged, and the end of the file will contain old data. In most cases, one should either use create_new to ensure the file is created from scratch, or ensure truncate is called so that the truncation behaviour is explicit. truncate(true) will ensure the file is entirely overwritten with new data, whereas truncate(false) will explicitly keep the default behavior. Clippy puts this lint in the suspicious group, at the level warn.
- Code
suspicious_open_options- Severity
- warn
- Since
- 1.77.0
They are probably bugs and if they aren’t then they look like bugs and you should add a comment explaining why you are doing such an odd set of operations. Clippy puts this lint in the nursery group, at the level allow.
- Code
suspicious_operation_groupings- Severity
- allow
- Since
- 1.50.0
These calls don’t actually split the value and are likely to be intended as a different number. Clippy puts this lint in the correctness group, at the level deny.
- Code
suspicious_splitn- Severity
- deny
- Since
- 1.54.0
Calling to_owned() on a Cow creates a clone of the Cow itself, without taking ownership of the Cow contents (i.e. it’s equivalent to calling Cow::clone). The similarly named into_owned method, on the other hand, clones the Cow contents, effectively turning any Cow::Borrowed into a Cow::Owned. Clippy puts this lint in the suspicious group, at the level warn.
- Code
suspicious_to_owned- Severity
- warn
- Since
- 1.65.0
It lints if there is no space between the binary and unary operators, but there is a space between the unary and its operand. This is either a typo in the binary operator or confusing. Clippy puts this lint in the suspicious group, at the level warn.
- Code
suspicious_unary_op_formatting- Severity
- warn
- Since
- 1.40.0
It will not trigger if any of the numbers are not in decimal. It’s most probably a typo and may lead to unexpected behaviours. Clippy puts this lint in the restriction group, at the level allow.
- Code
suspicious_xor_used_as_pow- Severity
- allow
- Since
- 1.67.0
When at least one parameter to swap is derived from a pointer it may overlap with the other. This would then lead to undefined behavior. Clippy puts this lint in the suspicious group, at the level warn.
- Code
swap_ptr_to_ref- Severity
- warn
- Since
- 1.63.0
Storing a new value in place of a temporary value which will be dropped right after the swap is an inefficient way of performing an assignment. The same result can be achieved by using a regular assignment. Clippy puts this lint in the complexity group, at the level warn.
- Code
swap_with_temporary- Severity
- warn
- Since
- 1.88.0
Readability. If the structure is only created to be updated, why not write the structure you want in the first place? Clippy puts this lint in the complexity group, at the level warn.
- Code
temporary_assignment- Severity
- warn
Code in examples marked as #[test] will somewhat surprisingly not be run by cargo test. If you really want to show how to test stuff in an example, mark it no_run to make the intent clear. Clippy puts this lint in the suspicious group, at the level warn.
- Code
test_attr_in_doctest- Severity
- warn
- Since
- 1.76.0
The idiomatic (and more performant) way of writing tests is inside a testing module (flagged with #[cfg(test)]), having test functions outside of this module is confusing and may lead to them being “hidden”. Clippy puts this lint in the restriction group, at the level allow.
- Code
tests_outside_test_module- Severity
- allow
- Since
- 1.70.0
This is a convoluted way of checking if a char is a digit. It’s more straight forward to use the dedicated is_digit method. Clippy puts this lint in the style group, at the level warn.
- Code
to_digit_is_some- Severity
- warn
- Since
- 1.41.0
Since the type implements Display, the use of to_string is unnecessary. Clippy puts this lint in the perf group, at the level warn.
- Code
to_string_in_format_args- Severity
- warn
- Since
- 1.58.0
This trait is automatically implemented for any type which implements the Display trait. As such, ToString shouldn’t be implemented directly: Display should be implemented instead, and you get the ToString implementation for free. Clippy puts this lint in the style group, at the level warn.
- Code
to_string_trait_impl- Severity
- warn
- Since
- 1.78.0
The todo! macro indicates the presence of unfinished code, so it should not be present in production code. Clippy puts this lint in the restriction group, at the level allow.
- Code
todo- Severity
- allow
- Since
- 1.40.0
Documentation will show the first paragraph of the docstring in the summary page of a module. Having a nice, short summary in the first paragraph is part of writing good docs. Clippy puts this lint in the nursery group, at the level allow.
- Code
too_long_first_doc_paragraph- Severity
- allow
- Since
- 1.82.0
Functions with lots of parameters are considered bad style and reduce readability (“what does the 5th parameter mean?”). Consider grouping some parameters into a new type. Clippy puts this lint in the complexity group, at the level warn.
- Code
too_many_arguments- Severity
- warn
Functions with a lot of lines are harder to understand due to having to look at a larger amount of code to understand what the function is doing. Consider splitting the body of the function into multiple functions. Clippy puts this lint in the pedantic group, at the level allow.
- Code
too_many_lines- Severity
- allow
- Since
- 1.34.0
The ref declaration makes the function take an owned value, but turns the argument into a reference (which means that the value is destroyed when exiting the function). This adds not much value: either take a reference type, or take an owned value and create references in the body. Clippy puts this lint in the style group, at the level warn.
- Code
toplevel_ref_arg- Severity
- warn
Zero-sized arrays aren’t very useful in Rust itself, so such a struct is likely being created to pass to C code or in some other situation where control over memory layout matters (for example, in conjunction with manual allocation to make it easy to compute the offset of the array). Either way, #[repr(C)] (or another repr attribute) is needed. Clippy puts this lint in the nursery group, at the level allow.
- Code
trailing_empty_array- Severity
- allow
- Since
- 1.58.0
Duplicate bounds makes the code less readable than specifying them only once. Clippy puts this lint in the nursery group, at the level allow.
- Code
trait_duplication_in_bounds- Severity
- allow
- Since
- 1.47.0
Not every byte slice is a valid UTF-8 string. Clippy puts this lint in the complexity group, at the level warn.
- Code
transmute_bytes_to_str- Severity
- warn
This might result in an invalid in-memory representation of a bool. Clippy puts this lint in the complexity group, at the level warn.
- Code
transmute_int_to_bool- Severity
- warn
Transmutes work on any types and thus might cause unsoundness when those types change elsewhere. new_unchecked only works for the appropriate types instead. Clippy puts this lint in the complexity group, at the level warn.
- Code
transmute_int_to_non_zero- Severity
- warn
- Since
- 1.69.0
Creating a null function pointer is undefined behavior. Clippy puts this lint in the correctness group, at the level deny.
- Code
transmute_null_to_fn- Severity
- deny
- Since
- 1.68.0
Transmutes are dangerous, and these can instead be written as casts. Clippy puts this lint in the pedantic group, at the level allow.
- Code
transmute_ptr_to_ptr- Severity
- allow
This can always be rewritten with & and *. Clippy puts this lint in the complexity group, at the level warn.
- Code
transmute_ptr_to_ref- Severity
- warn
The results of such a transmute are not defined. Clippy puts this lint in the nursery group, at the level allow.
- Code
transmute_undefined_repr- Severity
- allow
- Since
- 1.60.0
Readability. The code tricks people into thinking that something complex is going on. Clippy puts this lint in the complexity group, at the level warn.
- Code
transmutes_expressible_as_ptr_casts- Severity
- warn
- Since
- 1.47.0
Transmuting a null pointer is undefined behavior. Clippy puts this lint in the correctness group, at the level deny.
- Code
transmuting_null- Severity
- deny
- Since
- 1.35.0
split_whitespace already ignores leading and trailing whitespace. Clippy puts this lint in the style group, at the level warn.
- Code
trim_split_whitespace- Severity
- warn
- Since
- 1.62.0
Matching the regex can likely be replaced by == or str::starts_with, str::ends_with or std::contains or other str methods. Clippy puts this lint in the nursery group, at the level allow.
- Code
trivial_regex- Severity
- allow
In many calling conventions instances of structs will be passed through registers if they fit into two or less general purpose registers. Clippy puts this lint in the pedantic group, at the level allow.
- Code
trivially_copy_pass_by_ref- Severity
- allow
The ? operator is designed to allow calls that can fail to be easily chained. For example, foo()?.bar() or foo(bar()?). Because Err(x)? can’t be used that way (it will always return), it is more clear to write return Err(x). Clippy puts this lint in the restriction group, at the level allow.
- Code
try_err- Severity
- allow
- Since
- 1.38.0
It may be unnecessary complexity. .into() works for converting tuples<=> arrays of up to 12 elements and conveys the intent more clearly, while also leaving less room for hard to spot bugs! Clippy puts this lint in the nursery group, at the level allow.
- Code
tuple_array_conversions- Severity
- allow
- Since
- 1.72.0
Too complex types make the code less readable. Consider using a type definition to simplify them. Clippy puts this lint in the complexity group, at the level warn.
- Code
type_complexity- Severity
- warn
This almost certainly does not do what the user expects and can lead to subtle bugs. Calling .type_id() on a Box<dyn Trait> returns a fixed TypeId of the Box itself, rather than returning the TypeId of the underlying type behind the trait object. Clippy puts this lint in the suspicious group, at the level warn.
- Code
type_id_on_box- Severity
- warn
- Since
- 1.73.0
Repeating the type for every bound makes the code less readable than combining the bounds Clippy puts this lint in the nursery group, at the level allow.
- Code
type_repetition_in_bounds- Severity
- allow
- Since
- 1.38.0
The default implementation calls read for each byte, which can be very inefficient for data that’s not in memory, such as File. Clippy puts this lint in the perf group, at the level warn.
- Code
unbuffered_bytes- Severity
- warn
- Since
- 1.87.0
Unchecked subtraction could cause underflow on certain platforms, leading to unintentional panics. Clippy puts this lint in the pedantic group, at the level allow.
- Code
unchecked_time_subtraction- Severity
- allow
- Since
- 1.67.0
Infinite recursion in trait implementation will either cause crashes or result in an infinite loop, and it is hard to detect. Clippy puts this lint in the suspicious group, at the level warn.
- Code
unconditional_recursion- Severity
- warn
- Since
- 1.77.0
Undocumented unsafe blocks and impls can make it difficult to read and maintain code. Writing out the safety justification may help in discovering unsoundness or bugs. Clippy puts this lint in the restriction group, at the level allow.
- Code
undocumented_unsafe_blocks- Severity
- allow
- Since
- 1.58.0
If such a string is compared to another, the results may be surprising. Clippy puts this lint in the pedantic group, at the level allow.
- Code
unicode_not_nfc- Severity
- allow
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
unimplemented- Severity
- allow
Dereferencing a reference to an uninhabited type would create an instance of such a type, which cannot exist. This constitutes undefined behaviour. Such a reference could have been created by unsafe code. Clippy puts this lint in the nursery group, at the level allow.
- Code
uninhabited_references- Severity
- allow
- Since
- 1.76.0
For most types, this is undefined behavior. Clippy puts this lint in the correctness group, at the level deny.
- Code
uninit_assumed_init- Severity
- deny
- Since
- 1.39.0
This is commonly caused by calling set_len() right after allocating or reserving a buffer with new(), default(), with_capacity(), or reserve(). It creates a Vec with uninitialized data, which leads to undefined behavior with most safe operations. Notably, uninitialized Vec<u8> must not be used with generic Read. Clippy puts this lint in the correctness group, at the level deny.
- Code
uninit_vec- Severity
- deny
- Since
- 1.58.0
Non-inlined code is slightly more difficult to read and understand, as it requires arguments to be matched against the format string. The inlined syntax, where allowed, is simpler. Clippy puts this lint in the pedantic group, at the level allow.
- Code
uninlined_format_args- Severity
- allow
- Since
- 1.66.0
This is likely the result of an accidental semicolon. Clippy puts this lint in the complexity group, at the level warn.
- Code
unit_arg- Severity
- warn
This includes all binary comparisons (like == and <) and asserts. Unit is always equal to itself, and thus is just a clumsily written constant. Mostly this happens when someone accidentally adds semicolons at the end of the operands. Clippy puts this lint in the correctness group, at the level deny.
- Code
unit_cmp- Severity
- deny
Hashing a unit value doesn’t do anything as the implementation of Hash for () is a no-op. Clippy puts this lint in the correctness group, at the level deny.
- Code
unit_hash- Severity
- deny
- Since
- 1.58.0
The lint also suggests to remove the semi-colon at the end of the statement if present. Likely, returning the unit type is unintentional, and could simply be caused by an extra semi-colon. Since () implements Ord it doesn’t cause a compilation error. This is the same reasoning behind the unit_cmp lint. Clippy puts this lint in the correctness group, at the level deny.
- Code
unit_return_expecting_ord- Severity
- deny
- Since
- 1.47.0
It’s better to just return T in these cases. The caller may not need the value to be boxed, and it’s expensive to free the memory once the Box<T> been dropped. Clippy puts this lint in the pedantic group, at the level allow.
- Code
unnecessary_box_returns- Severity
- allow
- Since
- 1.70.0
It’s just unnecessary. Clippy puts this lint in the complexity group, at the level warn.
- Code
unnecessary_cast- Severity
- warn
There is no reason to put clippy attributes behind a clippy cfg as they are not run by anything else than clippy. Clippy puts this lint in the suspicious group, at the level warn.
- Code
unnecessary_clippy_cfg- Severity
- warn
- Since
- 1.78.0
Rust doesn’t guarantee what Debug formatting looks like, and it could change in the future. OsStrs and Paths can be Display formatted using their display methods. Clippy puts this lint in the pedantic group, at the level allow.
- Code
unnecessary_debug_formatting- Severity
- allow
- Since
- 1.87.0
In those cases, the TryInto and TryFrom trait implementation is a blanket impl that forwards to Into or From, which always succeeds. The returned Result<_, Infallible> requires error handling to get the contained value even though the conversion can never fail. Clippy puts this lint in the style group, at the level warn.
- Code
unnecessary_fallible_conversions- Severity
- warn
- Since
- 1.75.0
More specifically it checks if the closure provided is only performing one of the filter or map operations and suggests the appropriate option. Complexity. The intent is also clearer if only a single operation is being performed. Clippy puts this lint in the complexity group, at the level warn.
- Code
unnecessary_filter_map- Severity
- warn
- Since
- 1.31.0
More specifically it checks if the closure provided is only performing one of the find or map operations and suggests the appropriate option. Complexity. The intent is also clearer if only a single operation is being performed. Clippy puts this lint in the complexity group, at the level warn.
- Code
unnecessary_find_map- Severity
- warn
- Since
- 1.61.0
Using .is_empty() is shorter and better communicates the intention. Clippy puts this lint in the complexity group, at the level warn.
- Code
unnecessary_first_then_check- Severity
- warn
- Since
- 1.83.0
Specifically, this checks for folds which could be replaced by any, all, sum or product. Readability. Clippy puts this lint in the style group, at the level warn.
- Code
unnecessary_fold- Severity
- warn
It can be done in one call with .contains()/.contains_key(). Clippy puts this lint in the complexity group, at the level warn.
- Code
unnecessary_get_then_check- Severity
- warn
- Since
- 1.78.0
.collect::<String>() is more concise and might be more performant Clippy puts this lint in the pedantic group, at the level allow.
- Code
unnecessary_join- Severity
- allow
- Since
- 1.61.0
Using eager evaluation is shorter and simpler in some cases. Clippy puts this lint in the style group, at the level warn.
- Code
unnecessary_lazy_evaluations- Severity
- warn
- Since
- 1.48.0
This leaves the caller unable to use the &str as &'static str, causing unnecessary allocations or confusion. This is also most likely what you meant to write. Clippy puts this lint in the pedantic group, at the level allow.
- Code
unnecessary_literal_bound- Severity
- allow
- Since
- 1.84.0
It is better to write the value directly without the indirection. Clippy puts this lint in the complexity group, at the level warn.
- Code
unnecessary_literal_unwrap- Severity
- warn
- Since
- 1.72.0
It introduces unnecessary complexity. Instead, the function can be called before constructing the Option or Result from its return value. Clippy puts this lint in the complexity group, at the level warn.
- Code
unnecessary_map_on_constructor- Severity
- warn
- Since
- 1.74.0
Calls such as opt.map_or(false, |val| val == 5) are needlessly long and cumbersome, and can be reduced to, for example, opt == Some(5) assuming opt implements PartialEq. Also, calls such as opt.map_or(true, |val| val == 5) can be reduced to opt.is_none_or(|val| val == 5). This lint offers readability and conciseness improvements. Clippy puts this lint in the style group, at the level warn.
- Code
unnecessary_map_or- Severity
- warn
- Since
- 1.84.0
In the aforementioned cases it is not necessary to call min() or max() to compare values, it may even cause confusion. Clippy puts this lint in the complexity group, at the level warn.
- Code
unnecessary_min_or_max- Severity
- warn
- Since
- 1.81.0
The mutable reference rules out all other references to the value. Also the code misleads about the intent of the call site. Clippy puts this lint in the style group, at the level warn.
- Code
unnecessary_mut_passed- Severity
- warn
Expressions by themselves often have no side-effects. Having such expressions reduces readability. Clippy puts this lint in the complexity group, at the level warn.
- Code
unnecessary_operation- Severity
- warn
This can be written more concisely by using unwrap_or_else(). Clippy puts this lint in the suspicious group, at the level warn.
- Code
unnecessary_option_map_or_else- Severity
- warn
- Since
- 1.92.0
This results in longer and less readable code Clippy puts this lint in the style group, at the level warn.
- Code
unnecessary_owned_empty_strings- Severity
- warn
- Since
- 1.62.0
It might lead to unhandled fields when the struct changes. Clippy puts this lint in the restriction group, at the level allow.
- Code
unnecessary_rest_pattern- Severity
- allow
- Since
- 1.99.0
This can be written more concisely by using unwrap_or_else(). Clippy puts this lint in the suspicious group, at the level warn.
- Code
unnecessary_result_map_or_else- Severity
- warn
- Since
- 1.78.0
Safe functions and traits are safe to implement and therefore do not need to describe safety preconditions that users are required to uphold. Clippy puts this lint in the restriction group, at the level allow.
- Code
unnecessary_safety_doc- Severity
- allow
- Since
- 1.67.0
In most cases, this can be written much more cleanly by omitting ::{self}. Clippy puts this lint in the restriction group, at the level allow.
- Code
unnecessary_self_imports- Severity
- allow
- Since
- 1.53.0
The semicolon is not needed, and may be removed to avoid confusion and visual clutter. Clippy puts this lint in the pedantic group, at the level allow.
- Code
unnecessary_semicolon- Severity
- allow
- Since
- 1.86.0
It is more clear to use Vec::sort_by_key (or Vec::sort if possible) than to use Vec::sort_by and a more complicated closure. Clippy puts this lint in the complexity group, at the level warn.
- Code
unnecessary_sort_by- Severity
- warn
- Since
- 1.46.0
Readability suffers from unnecessary struct building. Clippy puts this lint in the nursery group, at the level allow.
- Code
unnecessary_struct_initialization- Severity
- allow
- Since
- 1.70.0
The unnecessary calls result in useless allocations. Clippy puts this lint in the perf group, at the level warn.
- Code
unnecessary_to_owned- Severity
- warn
- Since
- 1.59.0
The trailing comma is redundant and removing it is more consistent with how rustfmt formats regular function calls. Clippy puts this lint in the pedantic group, at the level allow.
- Code
unnecessary_trailing_comma- Severity
- allow
- Since
- 1.95.0
Using if let or match is more idiomatic. Clippy puts this lint in the complexity group, at the level warn.
- Code
unnecessary_unwrap- Severity
- warn
Calling the non-unchecked variant may result in checking that is then discarded if unwrap_unchecked is called directly afterwards, whereas the unchecked variant most likely avoids performing the check completely. Clippy puts this lint in the complexity group, at the level warn.
- Code
unnecessary_unwrap_unchecked- Severity
- warn
- Since
- 1.98.0
It is not meaningful to wrap values when no None or Err is returned. Clippy puts this lint in the pedantic group, at the level allow.
- Code
unnecessary_wraps- Severity
- allow
- Since
- 1.50.0
Using .. instead is shorter and leaves the focus on the fields that are actually bound. Clippy puts this lint in the restriction group, at the level allow.
- Code
unneeded_field_pattern- Severity
- allow
Struct pattern { } or { .. } is not needed for unit variant. Clippy puts this lint in the style group, at the level warn.
- Code
unneeded_struct_pattern- Severity
- warn
- Since
- 1.86.0
The wildcard pattern is unneeded as the rest pattern can match that element as well. Clippy puts this lint in the complexity group, at the level warn.
- Code
unneeded_wildcard_pattern- Severity
- warn
- Since
- 1.40.0
In the example above, Some is repeated, which unnecessarily complicates the pattern. Clippy puts this lint in the pedantic group, at the level allow.
- Code
unnested_or_patterns- Severity
- allow
- Since
- 1.46.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
unreachable- Severity
- allow
- Since
- 1.40.0
Reading long numbers is difficult without separators. Clippy puts this lint in the pedantic group, at the level allow.
- Code
unreadable_literal- Severity
- allow
Deriving serde::Deserialize will create a constructor that may violate invariants held by another constructor. Clippy puts this lint in the pedantic group, at the level allow.
- Code
unsafe_derive_deserialize- Severity
- allow
- Since
- 1.45.0
Renaming makes it less clear which traits and structures are unsafe. Clippy puts this lint in the style group, at the level warn.
- Code
unsafe_removed_from_name- Severity
- warn
Nothing. unsafe_vector_initialization
This lint has been deprecated Clippy puts this lint in the deprecated group, at the level none.
- Code
unsafe_vector_initialization- Severity
- none
To enforce unseparated literal suffix style, see the separated_literal_suffix lint. Suffix style should be consistent. Clippy puts this lint in the restriction group, at the level allow.
- Code
unseparated_literal_suffix- Severity
- allow
This is undefined behavior. Clippy puts this lint in the correctness group, at the level deny.
- Code
unsound_collection_transmute- Severity
- deny
- Since
- 1.40.0
Nothing. unstable_as_mut_slice
This lint has been deprecated Clippy puts this lint in the deprecated group, at the level none.
- Code
unstable_as_mut_slice- Severity
- none
Nothing. unstable_as_slice
This lint has been deprecated Clippy puts this lint in the deprecated group, at the level none.
- Code
unstable_as_slice- Severity
- none
Async functions with no async code create overhead, both mentally and computationally. Callers of async methods either need to be calling from an async function themselves or run it on an executor, both of which causes runtime overhead and hassle for the caller. Clippy puts this lint in the pedantic group, at the level allow.
- Code
unused_async- Severity
- allow
- Since
- 1.54.0
Async functions with no async code create computational overhead. Even though the trait requires the method to return a future, returning a core::future::ready with the result is more efficient as it reduces the number of states in the Future state machine by at least one. Clippy puts this lint in the pedantic group, at the level allow.
- Code
unused_async_trait_impl- Severity
- allow
- Since
- 1.98.0
This lint has been deprecated Clippy puts this lint in the deprecated group, at the level none.
- Code
unused_collect- Severity
- none
- Since
- 1.39.0
The index from .enumerate() is immediately dropped. Clippy puts this lint in the style group, at the level warn.
- Code
unused_enumerate_index- Severity
- warn
- Since
- 1.75.0
Shorter format specifiers are easier to read, it may also indicate that an expected formatting operation such as adding padding isn’t happening. Clippy puts this lint in the complexity group, at the level warn.
- Code
unused_format_specs- Severity
- warn
- Since
- 1.66.0
io::Write::write(_vectored) and io::Read::read(_vectored) are not guaranteed to process the entire buffer. They return how many bytes were processed, which might be smaller than a given buffer’s length. If you don’t need to deal with partial-write/read, use write_all/read_exact instead. Clippy puts this lint in the correctness group, at the level deny.
- Code
unused_io_amount- Severity
- deny
Creating a peekable iterator without using any of its methods is likely a mistake, or just a leftover after a refactor. Clippy puts this lint in the nursery group, at the level allow.
- Code
unused_peekable- Severity
- allow
- Since
- 1.65.0
Using Result::ok() may look like the result is checked like unwrap or expect would do but it only silences the warning caused by #[must_use] on the Result. Clippy puts this lint in the restriction group, at the level allow.
- Code
unused_result_ok- Severity
- allow
- Since
- 1.82.0
This is unnecessary and confusing to the reader. Doing this is probably a mistake. Clippy puts this lint in the nursery group, at the level allow.
- Code
unused_rounding- Severity
- allow
- Since
- 1.63.0
It may be clearer to define the method as an associated function instead of an instance method if it doesn’t require self. Clippy puts this lint in the pedantic group, at the level allow.
- Code
unused_self- Severity
- allow
- Since
- 1.40.0
Traits imported that aren’t used directly can be imported anonymously with use Trait as _. It is more explicit, avoids polluting the current scope with unused names and can be useful to show which imports are required for traits. Clippy puts this lint in the restriction group, at the level allow.
- Code
unused_trait_names- Severity
- allow
- Since
- 1.83.0
Such expressions add no value, but can make the code less readable. Depending on formatting they can make a break or return statement look like a function call. Clippy puts this lint in the style group, at the level warn.
- Code
unused_unit- Severity
- warn
- Since
- 1.31.0
Negatively impacts readability. Clippy puts this lint in the style group, at the level warn.
- Code
unusual_byte_groupings- Severity
- warn
- Since
- 1.49.0
These functions promote recoverable errors to non-recoverable errors, which may be undesirable in code bases which wish to avoid panics, or be a bug in the specific function. Clippy puts this lint in the restriction group, at the level allow.
- Code
unwrap_in_result- Severity
- allow
- Since
- 1.48.0
Readability. Using unwrap_or_default in place of unwrap_or/unwrap_or_else, or or_default in place of or_insert/or_insert_with, is simpler and more concise. Clippy puts this lint in the style group, at the level warn.
- Code
unwrap_or_default- Severity
- warn
- Since
- 1.56.0
It is better to handle the None or Err case, or at least call .expect(_) with a more helpful message. Still, for a lot of quick-and-dirty code, unwrap 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
unwrap_used- Severity
- allow
- Since
- 1.45.0