So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`...
And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun...
Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work.
```nu
mv v0.0.212 rust-1.00.0;
mv beta rust-1.57.0;
mv master rust-1.58.0;
let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path);
let versions = (
ls | where name =~ "rust-" | select name | format {name}/lints.json |
each { open $it | select id | insert version $it | str substring "5,11" version} |
group-by id | rotate counter-clockwise id version |
update version {get version | first 1} | flatten | select id version);
$paths | each { |row|
let version = ($versions | where id == ($row.id) | format {version})
let idu = ($row.id | str upcase)
$"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n pub ($idu),/}' ($row.path)"
} | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh";
```
And this still has some problems, but at this point I just want to be done -.-
/// if vec.len() <= 0 {}
/// if 100 > i32::MAX {}
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub ABSURD_EXTREME_COMPARISONS,
correctness,
"a comparison with a maximum or minimum value that is always true or false"
/// let x = std::f32::consts::PI;
/// let y = std::f64::consts::FRAC_1_PI;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub APPROX_CONSTANT,
correctness,
"the approximate of a known float constant (in `std::fXX::consts`)"
/// # let a = 0;
/// a + 1;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub INTEGER_ARITHMETIC,
restriction,
"any integer arithmetic expression which could overflow or panic"
/// # let a = 0.0;
/// a + 1.0;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub FLOAT_ARITHMETIC,
restriction,
"any floating-point arithmetic statement"
/// f(a.try_into().expect("Unexpected u16 overflow in f"));
/// ```
///
+ #[clippy::version = "1.41.0"]
pub AS_CONVERSIONS,
restriction,
"using a potentially dangerous silent `as` conversion"
/// asm!("lea ({}), {}", in(reg) ptr, lateout(reg) _, options(att_syntax));
/// # }
/// ```
+ #[clippy::version = "1.49.0"]
pub INLINE_ASM_X86_INTEL_SYNTAX,
restriction,
"prefer AT&T x86 assembly syntax"
/// asm!("lea {}, [{}]", lateout(reg) _, in(reg) ptr);
/// # }
/// ```
+ #[clippy::version = "1.49.0"]
pub INLINE_ASM_X86_ATT_SYNTAX,
restriction,
"prefer Intel x86 assembly syntax"
/// const B: bool = false;
/// assert!(B)
/// ```
+ #[clippy::version = "1.34.0"]
pub ASSERTIONS_ON_CONSTANTS,
style,
"`assert!(true)` / `assert!(false)` will be optimized out by the compiler, and should probably be replaced by a `panic!()` or `unreachable!()`"
/// // Good
/// a += b;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub ASSIGN_OP_PATTERN,
style,
"assigning the result of an operation on a variable to that same variable"
/// // ...
/// a += a + b;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MISREFACTORED_ASSIGN_OP,
suspicious,
"having a variable on both sides of an assign op"
/// };
/// }
/// ```
+ #[clippy::version = "1.48.0"]
pub ASYNC_YIELDS_ASYNC,
correctness,
"async blocks that return a type that can be awaited"
/// #[inline(always)]
/// fn not_quite_hot_code(..) { ... }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub INLINE_ALWAYS,
pedantic,
"use of `#[inline(always)]`"
/// #[macro_use]
/// extern crate baz;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub USELESS_ATTRIBUTE,
correctness,
"use of lint attributes on `extern crate` items"
/// #[deprecated(since = "forever")]
/// fn something_else() { /* ... */ }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub DEPRECATED_SEMVER,
correctness,
"use of `#[deprecated(since = \"x\")]` where x is not semver"
/// #[allow(dead_code)]
/// fn this_is_fine_too() { }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub EMPTY_LINE_AFTER_OUTER_ATTR,
nursery,
"empty line after outer attribute"
/// ```rust
/// #![deny(clippy::as_conversions)]
/// ```
+ #[clippy::version = "1.47.0"]
pub BLANKET_CLIPPY_RESTRICTION_LINTS,
suspicious,
"enabling the complete restriction group"
/// #[rustfmt::skip]
/// fn main() { }
/// ```
+ #[clippy::version = "1.32.0"]
pub DEPRECATED_CFG_ATTR,
complexity,
"usage of `cfg_attr(rustfmt)` instead of tool attributes"
/// fn conditional() { }
/// ```
/// Check the [Rust Reference](https://doc.rust-lang.org/reference/conditional-compilation.html#target_os) for more details.
+ #[clippy::version = "1.45.0"]
pub MISMATCHED_TARGET_OS,
correctness,
"usage of `cfg(operating_system)` instead of `cfg(target_os = \"operating_system\")`"
/// bar.await;
/// }
/// ```
+ #[clippy::version = "1.45.0"]
pub AWAIT_HOLDING_LOCK,
pedantic,
"Inside an async function, holding a MutexGuard while calling await"
/// bar.await;
/// }
/// ```
+ #[clippy::version = "1.49.0"]
pub AWAIT_HOLDING_REFCELL_REF,
pedantic,
"Inside an async function, holding a RefCell ref while calling await"
/// # let x = 1;
/// if (x & 1 == 2) { }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub BAD_BIT_MASK,
correctness,
"expressions of the form `_ & mask == select` that will only ever return `true` or `false`"
/// # let x = 1;
/// if (x | 1 > 3) { }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub INEFFECTIVE_BIT_MASK,
correctness,
"expressions where a bit mask will be rendered useless by a comparison, e.g., `(x | 1) > 2`"
/// # let x = 1;
/// if x & 0b1111 == 0 { }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub VERBOSE_BIT_MASK,
pedantic,
"expressions where a bit mask is less readable than the corresponding method call"
/// ```rust
/// let foo = 3.14;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub BLACKLISTED_NAME,
style,
"usage of a blacklisted/placeholder name"
/// let res = { let x = somefunc(); x };
/// if res { /* ... */ }
/// ```
+ #[clippy::version = "1.45.0"]
pub BLOCKS_IN_IF_CONDITIONS,
style,
"useless or complex blocks that can be eliminated in conditions"
/// // Good
/// assert!(!"a".is_empty());
/// ```
+ #[clippy::version = "1.53.0"]
pub BOOL_ASSERT_COMPARISON,
style,
"Using a boolean as comparison value in an assert_* macro when there is no need"
/// if a && true // should be: if a
/// if !(a == b) // should be: if a != b
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NONMINIMAL_BOOL,
complexity,
"boolean expressions that can be written more concisely"
/// if a && b || a { ... }
/// ```
/// The `b` is unnecessary, the expression is equivalent to `if a`.
+ #[clippy::version = "pre 1.29.0"]
pub LOGIC_BUG,
correctness,
"boolean expressions that contain terminals which can be eliminated"
/// # let vec = vec![1_u8];
/// &vec.iter().filter(|x| **x == 0u8).count(); // use bytecount::count instead
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NAIVE_BYTECOUNT,
pedantic,
"use of naive `<slice>.filter(|&x| x == y).count()` to count byte values"
/// keywords = ["clippy", "lint", "plugin"]
/// categories = ["development-tools", "development-tools::cargo-plugins"]
/// ```
+ #[clippy::version = "1.32.0"]
pub CARGO_COMMON_METADATA,
cargo,
"common metadata is defined in `Cargo.toml`"
/// filename.rsplit('.').next().map(|ext| ext.eq_ignore_ascii_case("rs")) == Some(true)
/// }
/// ```
+ #[clippy::version = "1.51.0"]
pub CASE_SENSITIVE_FILE_EXTENSION_COMPARISONS,
pedantic,
"Checks for calls to ends_with with case-sensitive file extensions"
/// let x = u64::MAX;
/// x as f64;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub CAST_PRECISION_LOSS,
pedantic,
"casts that cause loss of precision, e.g., `x as f32` where `x: u64`"
/// let y: i8 = -1;
/// y as u128; // will return 18446744073709551615
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub CAST_SIGN_LOSS,
pedantic,
"casts from signed types to unsigned types, e.g., `x as u32` where `x: i32`"
/// x as u8
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub CAST_POSSIBLE_TRUNCATION,
pedantic,
"casts that may cause truncation of the value, e.g., `x as u8` where `x: u32`, or `x as i32` where `x: f32`"
/// ```rust
/// u32::MAX as i32; // will yield a value of `-1`
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub CAST_POSSIBLE_WRAP,
pedantic,
"casts that may cause wrapping around the value, e.g., `x as i32` where `x: u32` and `x > i32::MAX`"
/// u64::from(x)
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub CAST_LOSSLESS,
pedantic,
"casts using `as` that are known to be lossless, e.g., `x as u64` where `x: u8`"
/// let _ = 2_i32;
/// let _ = 0.5_f32;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub UNNECESSARY_CAST,
complexity,
"cast to the same type, e.g., `x as i32` where `x: i32`"
/// (&1u8 as *const u8).cast::<u16>();
/// (&mut 1u8 as *mut u8).cast::<u16>();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub CAST_PTR_ALIGNMENT,
pedantic,
"cast from a pointer to a more-strictly-aligned pointer"
/// fn fun2() -> i32 { 1 }
/// let a = fun2 as usize;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub FN_TO_NUMERIC_CAST,
style,
"casting a function pointer to a numeric type other than usize"
/// let fn_ptr = fn2 as usize;
/// let fn_ptr_truncated = fn_ptr as i32;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
style,
"casting a function pointer to a numeric type not wide enough to store the address"
/// }
/// let _ = fn3 as fn() -> u16;
/// ```
+ #[clippy::version = "1.58.0"]
pub FN_TO_NUMERIC_CAST_ANY,
restriction,
"casting a function pointer to any integer type"
/// }
/// }
/// ```
+ #[clippy::version = "1.33.0"]
pub CAST_REF_TO_MUT,
correctness,
"a cast of reference to a mutable pointer"
/// ```rust,ignore
/// b'x'
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub CHAR_LIT_AS_U8,
complexity,
"casting a character literal to `u8` truncates"
/// let _ = ptr.cast::<i32>();
/// let _ = mut_ptr.cast::<i32>();
/// ```
+ #[clippy::version = "1.51.0"]
pub PTR_AS_PTR,
pedantic,
"casting using `as` from and to raw pointers that doesn't change its mutability, where `pointer::cast` could take the place of `as`"
/// i32::try_from(foo).is_ok()
/// # ;
/// ```
+ #[clippy::version = "1.37.0"]
pub CHECKED_CONVERSIONS,
pedantic,
"`try_from` could replace manual bounds checking when casting"
///
/// ### Example
/// No. You'll see it when you get the warning.
+ #[clippy::version = "1.35.0"]
pub COGNITIVE_COMPLEXITY,
nursery,
"functions that should be split up into multiple functions"
/// …
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub COLLAPSIBLE_IF,
style,
"nested `if`s that can be collapsed (e.g., `if x { if y { ... } }`"
/// …
/// }
/// ```
+ #[clippy::version = "1.51.0"]
pub COLLAPSIBLE_ELSE_IF,
style,
"nested `else`-`if` expressions that can be collapsed (e.g., `else { if x { ... } }`)"
/// };
/// }
/// ```
+ #[clippy::version = "1.50.0"]
pub COLLAPSIBLE_MATCH,
style,
"Nested `match` or `if let` expressions where the patterns may be \"collapsed\" together."
/// }
/// }
/// ```
+ #[clippy::version = "1.40.0"]
pub COMPARISON_CHAIN,
style,
"`if`s that can be rewritten with `match` and `cmp`"
/// …
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub IFS_SAME_COND,
correctness,
"consecutive `if`s with the same condition"
/// }
/// }
/// ```
+ #[clippy::version = "1.41.0"]
pub SAME_FUNCTIONS_IN_IF_CONDITION,
pedantic,
"consecutive `if`s with the same function call"
/// 42
/// };
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub IF_SAME_THEN_ELSE,
correctness,
"`if` with the same `then` and `else` blocks"
/// 42
/// };
/// ```
+ #[clippy::version = "1.53.0"]
pub BRANCHES_SHARING_CODE,
nursery,
"`if` statement with shared code in all blocks"
/// let a: Vec<_> = my_iterator.take(1).collect();
/// let b: Vec<_> = my_iterator.collect();
/// ```
+ #[clippy::version = "1.30.0"]
pub COPY_ITERATOR,
pedantic,
"implementing `Iterator` on a `Copy` type"
/// ```rust
/// std::fs::create_dir_all("foo");
/// ```
+ #[clippy::version = "1.48.0"]
pub CREATE_DIR,
restriction,
"calling `std::fs::create_dir` instead of `std::fs::create_dir_all`"
/// // Good
/// true
/// ```
+ #[clippy::version = "1.34.0"]
pub DBG_MACRO,
restriction,
"`dbg!` macro is intended as a debugging tool"
/// // Good
/// let s = String::default();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub DEFAULT_TRAIT_ACCESS,
pedantic,
"checks for literal calls to `Default::default()`"
/// .. Default::default()
/// };
/// ```
+ #[clippy::version = "1.49.0"]
pub FIELD_REASSIGN_WITH_DEFAULT,
style,
"binding initialized with Default should have its fields set in the initializer"
/// let i = 10i32;
/// let f = 1.23f64;
/// ```
+ #[clippy::version = "1.52.0"]
pub DEFAULT_NUMERIC_FALLBACK,
restriction,
"usage of unconstrained numeric literals which may cause default numeric fallback."
/// ```rust,ignore
/// let _ = d.unwrap().deref();
/// ```
+ #[clippy::version = "1.44.0"]
pub EXPLICIT_DEREF_METHODS,
pedantic,
"Explicit use of deref or deref_mut method while not in a method chain."
/// has exactly equal bounds, and therefore this lint is disabled for types with
/// generic parameters.
///
+ #[clippy::version = "1.57.0"]
pub DERIVABLE_IMPLS,
complexity,
"manual implementation of the `Default` trait which is equal to a derive"
/// ...
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub DERIVE_HASH_XOR_EQ,
correctness,
"deriving `Hash` but implementing `PartialEq` explicitly"
/// #[derive(Ord, PartialOrd, PartialEq, Eq)]
/// struct Foo;
/// ```
+ #[clippy::version = "1.47.0"]
pub DERIVE_ORD_XOR_PARTIAL_ORD,
correctness,
"deriving `Ord` but implementing `PartialOrd` explicitly"
/// // ..
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub EXPL_IMPL_CLONE_ON_COPY,
pedantic,
"implementing `Clone` explicitly on `Copy` types"
/// }
/// }
/// ```
+ #[clippy::version = "1.45.0"]
pub UNSAFE_DERIVE_DESERIALIZE,
pedantic,
"deriving `serde::Deserialize` on a type that has methods using `unsafe`"
/// let mut xs = Vec::new(); // Vec::new is _not_ disallowed in the config.
/// xs.push(123); // Vec::push is _not_ disallowed in the config.
/// ```
+ #[clippy::version = "1.49.0"]
pub DISALLOWED_METHOD,
nursery,
"use of a disallowed method call"
/// let zähler = 10; // OK, it's still latin.
/// let カウンタ = 10; // Will spawn the lint.
/// ```
+ #[clippy::version = "1.55.0"]
pub DISALLOWED_SCRIPT_IDENTS,
restriction,
"usage of non-allowed Unicode scripts"
/// // A similar type that is allowed by the config
/// use std::collections::HashMap;
/// ```
+ #[clippy::version = "1.55.0"]
pub DISALLOWED_TYPE,
nursery,
"use of a disallowed type"
/// /// [SmallVec]: SmallVec
/// fn main() {}
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub DOC_MARKDOWN,
pedantic,
"presence of `_`, `::` or camel-case outside backticks in documentation"
/// unimplemented!();
/// }
/// ```
+ #[clippy::version = "1.39.0"]
pub MISSING_SAFETY_DOC,
style,
"`pub unsafe fn` without `# Safety` docs"
/// unimplemented!();
/// }
/// ```
+ #[clippy::version = "1.41.0"]
pub MISSING_ERRORS_DOC,
pedantic,
"`pub fn` returns `Result` without `# Errors` in doc comment"
/// }
/// }
/// ```
+ #[clippy::version = "1.52.0"]
pub MISSING_PANICS_DOC,
pedantic,
"`pub fn` may panic without `# Panics` in doc comment"
/// unimplemented!();
/// }
/// ``````
+ #[clippy::version = "1.40.0"]
pub NEEDLESS_DOCTEST_MAIN,
style,
"presence of `fn main() {` in code examples"
/// # let y = 2;
/// if x <= y {}
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub DOUBLE_COMPARISONS,
complexity,
"unnecessary double comparisons that can be simplified"
/// // Good
/// foo(0);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub DOUBLE_PARENS,
complexity,
"Warn on unnecessary double parentheses"
/// // still locked
/// operation_that_requires_mutex_to_be_unlocked();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub DROP_REF,
correctness,
"calls to `std::mem::drop` with a reference instead of an owned value"
/// let x = Box::new(1);
/// std::mem::forget(&x) // Should have been forget(x), x will still be dropped
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub FORGET_REF,
correctness,
"calls to `std::mem::forget` with a reference instead of an owned value"
/// std::mem::drop(x) // A copy of x is passed to the function, leaving the
/// // original unaffected
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub DROP_COPY,
correctness,
"calls to `std::mem::drop` with a value that implements Copy"
/// std::mem::forget(x) // A copy of x is passed to the function, leaving the
/// // original unaffected
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub FORGET_COPY,
correctness,
"calls to `std::mem::forget` with a value that implements Copy"
/// let _micros = dur.subsec_micros();
/// let _millis = dur.subsec_millis();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub DURATION_SUBSEC,
complexity,
"checks for calculation of subsecond microseconds or milliseconds"
/// // We don't care about zero.
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub ELSE_IF_WITHOUT_ELSE,
restriction,
"`if` expression with an `else if`, but without a final `else` branch"
///
/// struct Test(!);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub EMPTY_ENUM,
pedantic,
"enum with no variants"
/// # let v = 1;
/// map.entry(k).or_insert(v);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MAP_ENTRY,
perf,
"use of `contains_key` followed by `insert` on a `HashMap` or `BTreeMap`"
/// Y = 0,
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub ENUM_CLIKE_UNPORTABLE_VARIANT,
correctness,
"C-like enums that are `repr(isize/usize)` and have values that don't fit into an `i32`"
/// Battenberg,
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub ENUM_VARIANT_NAMES,
style,
"enums where all variants share a prefix/postfix"
/// struct BlackForest;
/// }
/// ```
+ #[clippy::version = "1.33.0"]
pub MODULE_NAME_REPETITIONS,
pedantic,
"type names prefixed/postfixed with their containing module's name"
/// ...
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MODULE_INCEPTION,
style,
"modules that have the same name as their parent module"
/// # let b = 4;
/// assert_eq!(a, a);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub EQ_OP,
correctness,
"equal operands on both sides of a comparison or bitwise combination (e.g., `x == x`)"
/// // Good
/// x == *y
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub OP_REF,
style,
"taking a reference to satisfy the type constraints on `==`"
/// do_thing();
/// }
/// ```
+ #[clippy::version = "1.57.0"]
pub EQUATABLE_IF_LET,
nursery,
"using pattern matching instead of equality"
/// 0 * x;
/// x & 0;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub ERASING_OP,
correctness,
"using erasing operations, e.g., `x * 0` or `y & 0`"
/// foo(x);
/// println!("{}", x);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub BOXED_LOCAL,
perf,
"using `Box<T>` where unnecessary"
/// ```
/// where `foo(_)` is a plain function that takes the exact argument type of
/// `x`.
+ #[clippy::version = "pre 1.29.0"]
pub REDUNDANT_CLOSURE,
style,
"redundant closures, i.e., `|a| foo(a)` (which can be written as just `foo`)"
/// ```rust,ignore
/// Some('a').map(char::to_uppercase);
/// ```
+ #[clippy::version = "1.35.0"]
pub REDUNDANT_CLOSURE_FOR_METHOD_CALLS,
pedantic,
"redundant closures for method calls"
/// };
/// let a = tmp + x;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub EVAL_ORDER_DEPENDENCE,
suspicious,
"whether a variable read occurs before a write depends on sub-expression evaluation order"
/// let x = (a, b, c, panic!());
/// // can simply be replaced by `panic!()`
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub DIVERGING_SUB_EXPRESSION,
complexity,
"whether an expression contains a diverging sub expression"
/// Finished,
/// }
/// ```
+ #[clippy::version = "1.43.0"]
pub STRUCT_EXCESSIVE_BOOLS,
pedantic,
"using too many bools in a struct"
///
/// fn f(shape: Shape, temperature: Temperature) { ... }
/// ```
+ #[clippy::version = "1.43.0"]
pub FN_PARAMS_EXCESSIVE_BOOLS,
pedantic,
"using too many bools in function parameters"
/// Baz
/// }
/// ```
+ #[clippy::version = "1.51.0"]
pub EXHAUSTIVE_ENUMS,
restriction,
"detects exported enums that have not been marked #[non_exhaustive]"
/// baz: String,
/// }
/// ```
+ #[clippy::version = "1.51.0"]
pub EXHAUSTIVE_STRUCTS,
restriction,
"detects exported structs that have not been marked #[non_exhaustive]"
/// ```ignore
/// std::process::exit(0)
/// ```
+ #[clippy::version = "1.41.0"]
pub EXIT,
restriction,
"`std::process::exit` is called, terminating the program"
/// // this would be clearer as `eprintln!("foo: {:?}", bar);`
/// writeln!(&mut std::io::stderr(), "foo: {:?}", bar).unwrap();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub EXPLICIT_WRITE,
complexity,
"using the `write!()` family of functions instead of the `print!()` family of functions, when using the latter would work"
/// }
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub FALLIBLE_IMPL_FROM,
nursery,
"Warn on impls of `From<..>` that contain `panic!()` or `unwrap()`"
/// ghi = []
/// ```
///
+ #[clippy::version = "1.57.0"]
pub REDUNDANT_FEATURE_NAMES,
cargo,
"usage of a redundant feature name"
/// def = []
///
/// ```
+ #[clippy::version = "1.57.0"]
pub NEGATIVE_FEATURE_NAMES,
cargo,
"usage of a negative feature name"
/// (a - b).abs() < f32::EPSILON
/// }
/// ```
+ #[clippy::version = "1.48.0"]
pub FLOAT_EQUALITY_WITHOUT_ABS,
suspicious,
"float equality check without `.abs()`"
/// let v: f64 = 0.123_456_789_9;
/// println!("{}", v); // 0.123_456_789_9
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub EXCESSIVE_PRECISION,
style,
"excessive precision for float literal"
/// let _: f32 = 16_777_216.0;
/// let _: f64 = 16_777_217.0;
/// ```
+ #[clippy::version = "1.43.0"]
pub LOSSY_FLOAT_LITERAL,
restriction,
"lossy whole number float literals"
/// let _ = a.ln_1p();
/// let _ = a.exp_m1();
/// ```
+ #[clippy::version = "1.43.0"]
pub IMPRECISE_FLOPS,
nursery,
"usage of imprecise floating point operations"
/// let _ = a.abs();
/// let _ = -a.abs();
/// ```
+ #[clippy::version = "1.43.0"]
pub SUBOPTIMAL_FLOPS,
nursery,
"usage of sub-optimal floating point operations"
/// // Good
/// foo.to_owned();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub USELESS_FORMAT,
complexity,
"useless use of `format!`"
/// # use std::panic::Location;
/// println!("error: something failed at {}", Location::caller());
/// ```
+ #[clippy::version = "1.58.0"]
pub FORMAT_IN_FORMAT_ARGS,
perf,
"`format!` used in a macro that does formatting"
/// # use std::panic::Location;
/// println!("error: something failed at {}", Location::caller());
/// ```
+ #[clippy::version = "1.58.0"]
pub TO_STRING_IN_FORMAT_ARGS,
perf,
"`to_string` applied to a type that implements `Display` in format args"
/// ```rust,ignore
/// a =- 42; // confusing, should it be `a -= 42` or `a = -42`?
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub SUSPICIOUS_ASSIGNMENT_FORMATTING,
suspicious,
"suspicious formatting of `*=`, `-=` or `!=`"
/// if foo &&! bar { // this should be `foo && !bar` but looks like a different operator
/// }
/// ```
+ #[clippy::version = "1.40.0"]
pub SUSPICIOUS_UNARY_OP_FORMATTING,
suspicious,
"suspicious formatting of unary `-` or `!` on the RHS of a BinOp"
/// if bar { // this is the `else` block of the previous `if`, but should it be?
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub SUSPICIOUS_ELSE_FORMATTING,
suspicious,
"suspicious formatting of `else`"
/// -4, -5, -6
/// ];
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub POSSIBLE_MISSING_COMMA,
correctness,
"possible missing comma in array"
/// }
/// }
/// ```
+ #[clippy::version = "1.51.0"]
pub FROM_OVER_INTO,
style,
"Warns on implementations of `Into<..>` to use `From<..>`"
/// let input: &str = get_input();
/// let num: u16 = input.parse()?;
/// ```
+ #[clippy::version = "1.52.0"]
pub FROM_STR_RADIX_10,
style,
"from_str_radix with radix 10"
/// // ..
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub TOO_MANY_ARGUMENTS,
complexity,
"functions with too many arguments"
/// println!("");
/// }
/// ```
+ #[clippy::version = "1.34.0"]
pub TOO_MANY_LINES,
pedantic,
"functions with too many lines"
/// println!("{}", unsafe { *x });
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NOT_UNSAFE_PTR_ARG_DEREF,
correctness,
"public functions dereferencing raw pointer arguments but not marked `unsafe`"
/// #[must_use]
/// fn useless() { }
/// ```
+ #[clippy::version = "1.40.0"]
pub MUST_USE_UNIT,
style,
"`#[must_use]` attribute on a unit-returning function / method"
/// unimplemented!();
/// }
/// ```
+ #[clippy::version = "1.40.0"]
pub DOUBLE_MUST_USE,
style,
"`#[must_use]` attribute on a `#[must_use]`-returning function / method"
/// // this could be annotated with `#[must_use]`.
/// fn id<T>(t: T) -> T { t }
/// ```
+ #[clippy::version = "1.40.0"]
pub MUST_USE_CANDIDATE,
pedantic,
"function or method that could take a `#[must_use]` attribute"
///
/// Note that there are crates that simplify creating the error type, e.g.
/// [`thiserror`](https://docs.rs/thiserror).
+ #[clippy::version = "1.49.0"]
pub RESULT_UNIT_ERR,
style,
"public function returning `Result` with an `Err` type of `()`"
/// ```rust
/// async fn is_send(bytes: std::sync::Arc<[u8]>) {}
/// ```
+ #[clippy::version = "1.44.0"]
pub FUTURE_NOT_SEND,
nursery,
"public Futures must be Send"
/// let x = vec![2, 3, 5];
/// let last_element = x.last();
/// ```
+ #[clippy::version = "1.37.0"]
pub GET_LAST_WITH_LEN,
complexity,
"Using `x.get(x.len() - 1)` when `x.last()` is correct and simpler"
/// # let x = 1;
/// x / 1 + 0 * 1 - 0 | 0;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub IDENTITY_OP,
complexity,
"using identity operations, e.g., `x + 0` or `y / 1`"
/// use_locked(locked);
/// }
/// ```
+ #[clippy::version = "1.45.0"]
pub IF_LET_MUTEX,
correctness,
"locking a `Mutex` in an `if let` block can cause deadlocks"
/// a()
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub IF_NOT_ELSE,
pedantic,
"`if` branches that could be swapped so no negation operation is necessary on the condition"
/// 42
/// });
/// ```
+ #[clippy::version = "1.53.0"]
pub IF_THEN_SOME_ELSE_NONE,
restriction,
"Finds if-else that could be written using `bool::then`"
///
/// pub fn foo<S: BuildHasher>(map: &mut HashMap<i32, i32, S>) { }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub IMPLICIT_HASHER,
pedantic,
"missing generalization over different hashers"
/// return x;
/// }
/// ```
+ #[clippy::version = "1.33.0"]
pub IMPLICIT_RETURN,
restriction,
"use a return statement like `return expr` instead of an expression"
/// // Good
/// i = i.saturating_sub(1);
/// ```
+ #[clippy::version = "1.44.0"]
pub IMPLICIT_SATURATING_SUB,
pedantic,
"Perform saturating subtraction instead of implicitly checking lower bound of data type"
/// # let y = 2;
/// Foo { x, y };
/// ```
+ #[clippy::version = "1.52.0"]
pub INCONSISTENT_STRUCT_CONSTRUCTOR,
pedantic,
"the order of the field init shorthand is inconsistent with the order in the struct definition"
/// x[0];
/// x[3];
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub OUT_OF_BOUNDS_INDEXING,
correctness,
"out of bounds constant indexing"
/// y.get(10..);
/// y.get(..100);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub INDEXING_SLICING,
restriction,
"indexing/slicing usage"
///
/// iter::repeat(1_u8).collect::<Vec<_>>();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub INFINITE_ITER,
correctness,
"infinite iteration"
/// let infinite_iter = 0..;
/// [0..].iter().zip(infinite_iter.take_while(|x| *x > 5));
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MAYBE_INFINITE_ITER,
pedantic,
"possible infinite iteration"
/// fn other() {}
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MULTIPLE_INHERENT_IMPL,
restriction,
"Multiple inherent impl that could be grouped"
/// }
/// }
/// ```
+ #[clippy::version = "1.38.0"]
pub INHERENT_TO_STRING,
style,
"type implements inherent method `to_string()`, but should instead implement the `Display` trait"
/// }
/// }
/// ```
+ #[clippy::version = "1.38.0"]
pub INHERENT_TO_STRING_SHADOW_DISPLAY,
correctness,
"type implements inherent method `to_string()`, which gets shadowed by the implementation of the `Display` trait"
/// fn name(&self) -> &'static str;
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub INLINE_FN_WITHOUT_BODY,
correctness,
"use of `#[inline]` on trait methods without bodies"
/// # let y = 1;
/// if x > y {}
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub INT_PLUS_ONE,
complexity,
"instead of using `x >= y + 1`, use `x > y`"
/// let x = 3f32 / 2f32;
/// println!("{}", x);
/// ```
+ #[clippy::version = "1.37.0"]
pub INTEGER_DIVISION,
restriction,
"integer division may cause loss of precision"
/// let x: u8 = 1;
/// (x as u32) > 300;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub INVALID_UPCAST_COMPARISONS,
pedantic,
"a comparison involving an upcast which is always true or false"
/// foo(); // prints "foo"
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub ITEMS_AFTER_STATEMENTS,
pedantic,
"blocks where an item comes after a statement"
/// }
/// }
/// ```
+ #[clippy::version = "1.57.0"]
pub ITER_NOT_RETURNING_ITERATOR,
pedantic,
"methods named `iter` or `iter_mut` that do not return an `Iterator`"
/// // Good
/// pub static a = [0u32; 1_000_000];
/// ```
+ #[clippy::version = "1.44.0"]
pub LARGE_CONST_ARRAYS,
perf,
"large non-scalar const array may cause performance overhead"
/// B(Box<[i32; 8000]>),
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub LARGE_ENUM_VARIANT,
perf,
"large size difference between variants on an enum"
/// ```rust,ignore
/// let a = [0u32; 1_000_000];
/// ```
+ #[clippy::version = "1.41.0"]
pub LARGE_STACK_ARRAYS,
pedantic,
"allocating large arrays on stack may cause stack overflow"
/// ..
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub LEN_ZERO,
style,
"checking `.len() == 0` or `.len() > 0` (or similar) when `.is_empty()` could be used instead"
/// }
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub LEN_WITHOUT_IS_EMPTY,
style,
"traits or impls with a public `len` method but no corresponding `is_empty` method"
/// ..
/// }
/// ```
+ #[clippy::version = "1.49.0"]
pub COMPARISON_TO_EMPTY,
style,
"checking `x == \"\"` or `x == []` (or similar) when `.is_empty()` could be used instead"
/// None
/// };
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub USELESS_LET_IF_SEQ,
nursery,
"unidiomatic `let mut` declaration followed by initialization in `if`"
/// // is_ok() is marked #[must_use]
/// let _ = f().is_ok();
/// ```
+ #[clippy::version = "1.42.0"]
pub LET_UNDERSCORE_MUST_USE,
restriction,
"non-binding let on a `#[must_use]` expression"
/// ```rust,ignore
/// let _lock = mutex.lock();
/// ```
+ #[clippy::version = "1.43.0"]
pub LET_UNDERSCORE_LOCK,
correctness,
"non-binding let on a synchronization lock"
/// // dropped at end of scope
/// }
/// ```
+ #[clippy::version = "1.50.0"]
pub LET_UNDERSCORE_DROP,
pedantic,
"non-binding let on a type that implements `Drop`"
/// x
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NEEDLESS_LIFETIMES,
complexity,
"using explicit lifetimes for references in function arguments when elision rules \
/// // ...
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub EXTRA_UNUSED_LIFETIMES,
complexity,
"unused lifetimes in function definitions"
/// // Good
/// let x: u64 = 61_864_918_973_511;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub UNREADABLE_LITERAL,
pedantic,
"long literal without underscores"
/// // Good
/// 2_i32;
/// ```
+ #[clippy::version = "1.30.0"]
pub MISTYPED_LITERAL_SUFFIXES,
correctness,
"mistyped literal suffix"
/// // Good
/// let x: u64 = 61_864_918_973_511;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub INCONSISTENT_DIGIT_GROUPING,
style,
"integer literals with digits grouped inconsistently"
/// let x: u32 = 0xFFF_FFF;
/// let y: u8 = 0b01_011_101;
/// ```
+ #[clippy::version = "1.49.0"]
pub UNUSUAL_BYTE_GROUPINGS,
style,
"binary or hex literals that aren't grouped by four"
/// ```rust
/// let x: u64 = 6186491_8973511;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub LARGE_DIGIT_GROUPS,
pedantic,
"grouping digits into groups that are too large"
/// `255` => `0xFF`
/// `65_535` => `0xFFFF`
/// `4_042_322_160` => `0xF0F0_F0F0`
+ #[clippy::version = "pre 1.29.0"]
pub DECIMAL_LITERAL_REPRESENTATION,
restriction,
"using decimal representation when hexadecimal would be better"
/// # let mut dst = vec![0; 65];
/// dst[64..(src.len() + 64)].clone_from_slice(&src[..]);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MANUAL_MEMCPY,
perf,
"manually copying items between slices"
/// println!("{}", i);
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NEEDLESS_RANGE_LOOP,
style,
"for-looping over a range of indices where an iterator over items would do"
/// // ..
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub EXPLICIT_ITER_LOOP,
pedantic,
"for-looping over `_.iter()` or `_.iter_mut()` when `&_` or `&mut _` would do"
/// // ..
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub EXPLICIT_INTO_ITER_LOOP,
pedantic,
"for-looping over `_.into_iter()` when `_` would do"
/// ..
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub ITER_NEXT_LOOP,
correctness,
"for-looping over `_.next()` which is probably not intended"
/// // ..
/// }
/// ```
+ #[clippy::version = "1.45.0"]
pub FOR_LOOPS_OVER_FALLIBLES,
suspicious,
"for-looping over an `Option` or a `Result`, which is more clearly expressed as an `if let`"
/// // .. do something with x
/// };
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub WHILE_LET_LOOP,
complexity,
"`loop { if let { ... } else break }`, which can be written as a `while let` loop"
/// // should be
/// let len = iterator.count();
/// ```
+ #[clippy::version = "1.30.0"]
pub NEEDLESS_COLLECT,
perf,
"collecting an iterator when collect is not needed"
/// # fn bar(bar: usize, baz: usize) {}
/// for (i, item) in v.iter().enumerate() { bar(i, *item); }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub EXPLICIT_COUNTER_LOOP,
complexity,
"for-looping with an explicit counter when `_.enumerate()` would do"
/// ```no_run
/// loop {}
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub EMPTY_LOOP,
suspicious,
"empty `loop {}`, which should block or sleep"
/// ..
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub WHILE_LET_ON_ITERATOR,
style,
"using a `while let` loop instead of a for loop on an iterator"
/// ..
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub FOR_KV_MAP,
style,
"looping on a map using `iter` when `keys` or `values` would do"
/// break;
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NEVER_LOOP,
correctness,
"any loop that will always `break` or `return`"
/// println!("{}", i); // prints numbers from 0 to 42, not 0 to 21
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MUT_RANGE_BOUND,
suspicious,
"for loop over a range where one of the bounds is a mutable variable"
/// println!("let me loop forever!");
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub WHILE_IMMUTABLE_CONDITION,
correctness,
"variables used within while expression are not mutated in the body"
/// let mut vec: Vec<u8> = vec![item1; 20];
/// vec.resize(20 + 30, item2);
/// ```
+ #[clippy::version = "1.47.0"]
pub SAME_ITEM_PUSH,
style,
"the same item is pushed inside of a for loop"
/// let item = &item1;
/// println!("{}", item);
/// ```
+ #[clippy::version = "1.49.0"]
pub SINGLE_ELEMENT_LOOP,
complexity,
"there is no reason to have a single element loop"
/// println!("{}", n);
/// }
/// ```
+ #[clippy::version = "1.52.0"]
pub MANUAL_FLATTEN,
complexity,
"for loops over `Option`s or `Result`s with a single expression can be simplified"
/// #[macro_use]
/// use some_macro;
/// ```
+ #[clippy::version = "1.44.0"]
pub MACRO_USE_IMPORTS,
pedantic,
"#[macro_use] is no longer needed"
/// main();
/// }
/// ```
+ #[clippy::version = "1.38.0"]
pub MAIN_RECURSION,
style,
"recursion using the entrypoint"
/// let sad_people: Vec<&str> = vec![];
/// assert!(sad_people.is_empty(), "there are sad people: {:?}", sad_people);
/// ```
+ #[clippy::version = "1.57.0"]
pub MANUAL_ASSERT,
pedantic,
"`panic!` and only a `panic!` in `if`-then statement"
/// ```rust
/// async fn foo() -> i32 { 42 }
/// ```
+ #[clippy::version = "1.45.0"]
pub MANUAL_ASYNC_FN,
style,
"manual implementations of `async` functions can be simplified using the dedicated syntax"
/// ```rust
/// Some(0).map(|x| x + 1);
/// ```
+ #[clippy::version = "1.52.0"]
pub MANUAL_MAP,
style,
"reimplementation of `map`"
/// #[non_exhaustive]
/// struct T(pub i32, pub i32);
/// ```
+ #[clippy::version = "1.45.0"]
pub MANUAL_NON_EXHAUSTIVE,
style,
"manual implementations of the non-exhaustive pattern can be simplified using #[non_exhaustive]"
/// let foo: Option<i32> = None;
/// foo.ok_or("error");
/// ```
+ #[clippy::version = "1.49.0"]
pub MANUAL_OK_OR,
pedantic,
"finds patterns that can be encoded more concisely with `Option::ok_or`"
/// assert_eq!(end.to_uppercase(), "WORLD!");
/// }
/// ```
+ #[clippy::version = "1.48.0"]
pub MANUAL_STRIP,
complexity,
"suggests using `strip_{prefix,suffix}` over `str::{starts,ends}_with` and slicing"
/// let foo: Option<i32> = None;
/// foo.unwrap_or(1);
/// ```
+ #[clippy::version = "1.49.0"]
pub MANUAL_UNWRAP_OR,
complexity,
"finds patterns that can be encoded more concisely with `Option::unwrap_or` or `Result::unwrap_or`"
/// let y = x.iter();
/// let z = y.cloned();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MAP_CLONE,
style,
"using `iterator.map(|x| x.clone())`, or dereferencing closures for `Copy` types"
/// })
/// }
/// ```
+ #[clippy::version = "1.48.0"]
pub MAP_ERR_IGNORE,
restriction,
"`map_err` should not ignore the original error"
/// log_err_msg(format_msg(msg));
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub OPTION_MAP_UNIT_FN,
complexity,
"using `option.map(f)`, where `f` is a function or closure that returns `()`"
/// log_err_msg(format_msg(msg));
/// };
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub RESULT_MAP_UNIT_FN,
complexity,
"using `result.map(f)`, where `f` is a function or closure that returns `()`"
/// _ => {},
/// }
/// ```
+ #[clippy::version = "1.45.0"]
pub MATCH_ON_VEC_ITEMS,
pedantic,
"matching on vector elements can panic"
/// vec.push(value)
/// }
/// ```
+ #[clippy::version = "1.57.0"]
pub MATCH_RESULT_OK,
style,
"usage of `ok()` in `let Some(pat)` statements is unnecessary, match on `Ok(pat)` instead"
/// _ => {},
/// }
/// ```
+ #[clippy::version = "1.58.0"]
pub MATCH_STR_CASE_MISMATCH,
correctness,
"creation of a case altering match expression with non-compliant arms"
/// bar(foo);
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub SINGLE_MATCH,
style,
"a `match` statement with a single nontrivial arm (i.e., where the other arm is `_ => {}`) instead of `if let`"
/// bar(&other_ref);
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub SINGLE_MATCH_ELSE,
pedantic,
"a `match` statement with two arms where the second arm's pattern is a placeholder instead of a specific match pattern"
/// _ => frob(x),
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MATCH_REF_PATS,
style,
"a `match` or `if let` with all arms prefixed with `&` instead of deref-ing the match expression"
/// bar();
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MATCH_BOOL,
pedantic,
"a `match` on a boolean expression instead of an `if..else` block"
/// _ => (),
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MATCH_OVERLAPPING_ARM,
style,
"a `match` with overlapping arms"
/// Err(_) => panic!("err"),
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MATCH_WILD_ERR_ARM,
pedantic,
"a `match` with `Err(_)` arm and take drastic actions"
/// // Good
/// let r: Option<&()> = x.as_ref();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MATCH_AS_REF,
complexity,
"a `match` on an Option value instead of using `as_ref()` or `as_mut`"
/// Foo::B(_) => {},
/// }
/// ```
+ #[clippy::version = "1.34.0"]
pub WILDCARD_ENUM_MATCH_ARM,
restriction,
"a wildcard enum match arm using `_`"
/// Foo::C => {},
/// }
/// ```
+ #[clippy::version = "1.45.0"]
pub MATCH_WILDCARD_FOR_SINGLE_VARIANTS,
pedantic,
"a wildcard enum match for a single variant"
/// _ => {},
/// }
/// ```
+ #[clippy::version = "1.42.0"]
pub WILDCARD_IN_OR_PATTERNS,
complexity,
"a wildcard pattern used with others patterns in same match arm"
/// let wrapper = Wrapper::Data(42);
/// let Wrapper::Data(data) = wrapper;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub INFALLIBLE_DESTRUCTURING_MATCH,
style,
"a `match` statement with a single infallible arm instead of a `let`"
/// // Good
/// let (c, d) = (a, b);
/// ```
+ #[clippy::version = "1.43.0"]
pub MATCH_SINGLE_BINDING,
complexity,
"a match with a single binding instead of using `let` statement"
/// _ => {},
/// }
/// ```
+ #[clippy::version = "1.43.0"]
pub REST_PAT_IN_FULLY_BOUND_STRUCTS,
restriction,
"a match on a struct that binds all fields but still uses the wildcard pattern"
/// if IpAddr::V6(Ipv6Addr::LOCALHOST).is_ipv6() {}
/// Ok::<i32, i32>(42).is_ok();
/// ```
+ #[clippy::version = "1.31.0"]
pub REDUNDANT_PATTERN_MATCHING,
style,
"use the proper utility function avoiding an `if let`"
/// // Good
/// let a = matches!(x, Some(0));
/// ```
+ #[clippy::version = "1.47.0"]
pub MATCH_LIKE_MATCHES_MACRO,
style,
"a match that could be written with the matches! macro"
/// Quz => quz(),
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MATCH_SAME_ARMS,
pedantic,
"`match` with identical arm bodies"
/// # use std::rc::Rc;
/// mem::forget(Rc::new(55))
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MEM_FORGET,
restriction,
"`mem::forget` usage on `Drop` types, likely to cause memory leaks"
/// let mut an_option = Some(0);
/// let taken = an_option.take();
/// ```
+ #[clippy::version = "1.31.0"]
pub MEM_REPLACE_OPTION_WITH_NONE,
style,
"replacing an `Option` with `None` instead of `take()`"
/// The [take_mut](https://docs.rs/take_mut) crate offers a sound solution,
/// at the cost of either lazily creating a replacement value or aborting
/// on panic, to ensure that the uninitialized value cannot be observed.
+ #[clippy::version = "1.39.0"]
pub MEM_REPLACE_WITH_UNINIT,
correctness,
"`mem::replace(&mut _, mem::uninitialized())` or `mem::replace(&mut _, mem::zeroed())`"
/// let mut text = String::from("foo");
/// let taken = std::mem::take(&mut text);
/// ```
+ #[clippy::version = "1.42.0"]
pub MEM_REPLACE_WITH_DEFAULT,
style,
"replacing a value of type `T` with `T::default()` instead of using `std::mem::take`"
/// ```rust
/// [1, 2, 3].iter().copied();
/// ```
+ #[clippy::version = "1.53.0"]
pub CLONED_INSTEAD_OF_COPIED,
pedantic,
"used `cloned` where `copied` could be used instead"
/// ```rust
/// let nums: Vec<i32> = ["1", "2", "whee!"].iter().filter_map(|x| x.parse().ok()).collect();
/// ```
+ #[clippy::version = "1.53.0"]
pub FLAT_MAP_OPTION,
pedantic,
"used `flat_map` where `filter_map` could be used instead"
/// // Good
/// res.expect("more helpful message");
/// ```
+ #[clippy::version = "1.45.0"]
pub UNWRAP_USED,
restriction,
"using `.unwrap()` on `Result` or `Option`, which should at least get a better message using `expect()`"
/// res?;
/// # Ok::<(), ()>(())
/// ```
+ #[clippy::version = "1.45.0"]
pub EXPECT_USED,
restriction,
"using `.expect()` on `Result` or `Option`, which might be better handled"
/// }
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub SHOULD_IMPLEMENT_TRAIT,
style,
"defining a method that should be implementing a std trait"
/// }
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub WRONG_SELF_CONVENTION,
style,
"defining a method named with an established prefix (like \"into_\") that takes `self` with the wrong convention"
/// // Good
/// x.expect("why did I do this again?");
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub OK_EXPECT,
style,
"using `ok().expect()`, which gives worse error messages than calling `expect` directly on the Result"
/// // Good
/// x.unwrap_or_default();
/// ```
+ #[clippy::version = "1.56.0"]
pub UNWRAP_OR_ELSE_DEFAULT,
style,
"using `.unwrap_or_else(Default::default)`, which is more succinctly expressed as `.unwrap_or_default()`"
/// // Good
/// x.map_or_else(some_function, |a| a + 1);
/// ```
+ #[clippy::version = "1.45.0"]
pub MAP_UNWRAP_OR,
pedantic,
"using `.map(f).unwrap_or(a)` or `.map(f).unwrap_or_else(func)`, which are more succinctly expressed as `map_or(a, f)` or `map_or_else(a, f)`"
/// // Good
/// opt.and_then(|a| Some(a + 1));
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub OPTION_MAP_OR_NONE,
style,
"using `Option.map_or(None, f)`, which is more succinctly expressed as `and_then(f)`"
/// # let r: Result<u32, &str> = Ok(1);
/// assert_eq!(Some(1), r.ok());
/// ```
+ #[clippy::version = "1.44.0"]
pub RESULT_MAP_OR_INTO_OPTION,
style,
"using `Result.map_or(None, Some)`, which is more succinctly expressed as `ok()`"
/// let _ = res().map(|s| if s.len() == 42 { 10 } else { 20 });
/// let _ = res().map_err(|s| if s.len() == 42 { 10 } else { 20 });
/// ```
+ #[clippy::version = "1.45.0"]
pub BIND_INSTEAD_OF_MAP,
complexity,
"using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)`"
/// # let vec = vec![1];
/// vec.iter().find(|x| **x == 0);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub FILTER_NEXT,
complexity,
"using `filter(p).next()`, which is more succinctly expressed as `.find(p)`"
/// # let vec = vec![1];
/// vec.iter().find(|x| **x != 0);
/// ```
+ #[clippy::version = "1.42.0"]
pub SKIP_WHILE_NEXT,
complexity,
"using `skip_while(p).next()`, which is more succinctly expressed as `.find(!p)`"
/// // Good
/// vec.iter().flat_map(|x| x.iter());
/// ```
+ #[clippy::version = "1.31.0"]
pub MAP_FLATTEN,
pedantic,
"using combinations of `flatten` and `map` which can usually be written as a single method call"
/// ```rust
/// (0_i32..10).filter_map(|n| n.checked_add(1));
/// ```
+ #[clippy::version = "1.51.0"]
pub MANUAL_FILTER_MAP,
complexity,
"using `_.filter(_).map(_)` in a way that can be written more simply as `filter_map(_)`"
/// ```rust
/// (0_i32..10).find_map(|n| n.checked_add(1));
/// ```
+ #[clippy::version = "1.51.0"]
pub MANUAL_FIND_MAP,
complexity,
"using `_.find(_).map(_)` in a way that can be written more simply as `find_map(_)`"
/// ```rust
/// (0..3).find_map(|x| if x == 2 { Some(x) } else { None });
/// ```
+ #[clippy::version = "1.36.0"]
pub FILTER_MAP_NEXT,
pedantic,
"using combination of `filter_map` and `next` which can usually be written as a single method call"
/// # let iter = vec![vec![0]].into_iter();
/// iter.flatten();
/// ```
+ #[clippy::version = "1.39.0"]
pub FLAT_MAP_IDENTITY,
complexity,
"call to `flat_map` where `flatten` is sufficient"
///
/// let _ = !"hello world".contains("world");
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub SEARCH_IS_SOME,
complexity,
"using an iterator or string search followed by `is_some()` or `is_none()`, which is more succinctly expressed as a call to `any()` or `contains()` (with negation in case of `is_none()`)"
/// let name = "foo";
/// if name.starts_with('_') {};
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub CHARS_NEXT_CMP,
style,
"using `.chars().next()` to check if a string starts with a char"
/// # let foo = Some(String::new());
/// foo.unwrap_or_default();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub OR_FUN_CALL,
perf,
"using any `*or` method with a function call, which suggests `*or_else`"
/// # let err_msg = "I'm a teapot";
/// foo.unwrap_or_else(|| panic!("Err {}: {}", err_code, err_msg));
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub EXPECT_FUN_CALL,
perf,
"using any `expect` method with a function call"
/// ```rust
/// 42u64.clone();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub CLONE_ON_COPY,
complexity,
"using `clone` on a `Copy` type"
/// // Good
/// Rc::clone(&x);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub CLONE_ON_REF_PTR,
restriction,
"using 'clone' on a ref-counted pointer"
/// println!("{:p} {:p}", *y, z); // prints out the same pointer
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub CLONE_DOUBLE_REF,
correctness,
"using `clone` on `&&T`"
/// // OK, the specialized impl is used
/// ["foo", "bar"].iter().map(|&s| s.to_string());
/// ```
+ #[clippy::version = "1.40.0"]
pub INEFFICIENT_TO_STRING,
pedantic,
"using `to_string` on `&&T` where `T: ToString`"
/// fn new() -> Self;
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NEW_RET_NO_SELF,
style,
"not returning type containing `Self` in a `new` method"
///
/// // Good
/// _.split('x');
+ #[clippy::version = "pre 1.29.0"]
pub SINGLE_CHAR_PATTERN,
perf,
"using a single-character str where a char could be used, e.g., `_.split(\"x\")`"
/// //..
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub ITERATOR_STEP_BY_ZERO,
correctness,
"using `Iterator::step_by(0)`, which will panic at runtime"
/// ```rust
/// let _ = std::iter::empty::<Option<i32>>().flatten();
/// ```
+ #[clippy::version = "1.53.0"]
pub OPTION_FILTER_MAP,
complexity,
"filtering `Option` for `Some` then force-unwrapping, which can be one type-safe operation"
/// # s.insert(1);
/// let x = s.iter().next();
/// ```
+ #[clippy::version = "1.42.0"]
pub ITER_NTH_ZERO,
style,
"replace `iter.nth(0)` with `iter.next()`"
/// let bad_vec = some_vec.get(3);
/// let bad_slice = &some_vec[..].get(3);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub ITER_NTH,
perf,
"using `.iter().nth()` on a standard library type with O(1) element access"
/// let bad_vec = some_vec.iter().nth(3);
/// let bad_slice = &some_vec[..].iter().nth(3);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub ITER_SKIP_NEXT,
style,
"using `.skip(x).next()` on an iterator"
/// let last = some_vec[3];
/// some_vec[0] = 1;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub GET_UNWRAP,
restriction,
"using `.get().unwrap()` or `.get_mut().unwrap()` when using `[]` would work instead"
/// // Good
/// a.append(&mut b);
/// ```
+ #[clippy::version = "1.55.0"]
pub EXTEND_WITH_DRAIN,
perf,
"using vec.append(&mut vec) to move the full range of a vecor to another"
/// s.push_str(abc);
/// s.push_str(&def);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub STRING_EXTEND_CHARS,
style,
"using `x.extend(s.chars())` where s is a `&str` or `String`"
/// let s = [1, 2, 3, 4, 5];
/// let s2: Vec<isize> = s.to_vec();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub ITER_CLONED_COLLECT,
style,
"using `.cloned().collect()` on slice to create a `Vec`"
/// // Good
/// name.ends_with('_') || name.ends_with('-');
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub CHARS_LAST_CMP,
style,
"using `.chars().last()` or `.chars().next_back()` to check if a string ends with a char"
/// let x: &[i32] = &[1, 2, 3, 4, 5];
/// do_stuff(x);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub USELESS_ASREF,
complexity,
"using `as_ref` where the types before and after the call are the same"
/// ```rust
/// let _ = (0..3).any(|x| x > 2);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub UNNECESSARY_FOLD,
style,
"using `fold` when a more succinct alternative exists"
/// // As there is no conditional check on the argument this could be written as:
/// let _ = (0..4).map(|x| x + 1);
/// ```
+ #[clippy::version = "1.31.0"]
pub UNNECESSARY_FILTER_MAP,
complexity,
"using `filter_map` when a more succinct alternative exists"
/// // Good
/// let _ = (&vec![3, 4, 5]).iter();
/// ```
+ #[clippy::version = "1.32.0"]
pub INTO_ITER_ON_REF,
style,
"using `.into_iter()` on a reference"
/// ```rust
/// let _ = (0..3).map(|x| x + 2).count();
/// ```
+ #[clippy::version = "1.39.0"]
pub SUSPICIOUS_MAP,
suspicious,
"suspicious usage of map"
/// MaybeUninit::uninit().assume_init()
/// };
/// ```
+ #[clippy::version = "1.39.0"]
pub UNINIT_ASSUMED_INIT,
correctness,
"`MaybeUninit::uninit().assume_init()`"
/// let add = x.saturating_add(y);
/// let sub = x.saturating_sub(y);
/// ```
+ #[clippy::version = "1.39.0"]
pub MANUAL_SATURATING_ARITHMETIC,
style,
"`.chcked_add/sub(x).unwrap_or(MAX/MIN)`"
/// ```rust
/// unsafe { (&() as *const ()).offset(1) };
/// ```
+ #[clippy::version = "1.41.0"]
pub ZST_OFFSET,
correctness,
"Check for offset calculations on raw pointers to zero-sized types"
/// # Ok::<_, std::io::Error>(())
/// # };
/// ```
+ #[clippy::version = "1.42.0"]
pub FILETYPE_IS_FILE,
restriction,
"`FileType::is_file` is not recommended to test for readable file type"
/// opt.as_deref()
/// # ;
/// ```
+ #[clippy::version = "1.42.0"]
pub OPTION_AS_REF_DEREF,
complexity,
"using `as_ref().map(Deref::deref)`, which is more succinctly expressed as `as_deref()`"
/// a.get(2);
/// b.get(0);
/// ```
+ #[clippy::version = "1.46.0"]
pub ITER_NEXT_SLICE,
style,
"using `.iter().next()` on a sliced array, which can be shortened to just `.get()`"
/// string.insert(0, 'R');
/// string.push('R');
/// ```
+ #[clippy::version = "1.49.0"]
pub SINGLE_CHAR_ADD_STR,
style,
"`push_str()` or `insert_str()` used with a single-character string literal as parameter"
///
/// opt.unwrap_or(42);
/// ```
+ #[clippy::version = "1.48.0"]
pub UNNECESSARY_LAZY_EVALUATIONS,
style,
"using unnecessary lazy evaluation, which can be replaced with simpler eager evaluation"
/// ```rust
/// (0..3).try_for_each(|t| Err(t));
/// ```
+ #[clippy::version = "1.49.0"]
pub MAP_COLLECT_RESULT_UNIT,
style,
"using `.map(_).collect::<Result<(),_>()`, which can be replaced with `try_for_each`"
///
/// assert_eq!(v, vec![5, 5, 5, 5, 5]);
/// ```
+ #[clippy::version = "1.49.0"]
pub FROM_ITER_INSTEAD_OF_COLLECT,
pedantic,
"use `.collect()` instead of `::from_iter()`"
/// assert!(x >= 0);
/// });
/// ```
+ #[clippy::version = "1.51.0"]
pub INSPECT_FOR_EACH,
complexity,
"using `.inspect().for_each()`, which can be replaced with `.for_each()`"
/// # let iter = vec![Some(1)].into_iter();
/// iter.flatten();
/// ```
+ #[clippy::version = "1.52.0"]
pub FILTER_MAP_IDENTITY,
complexity,
"call to `filter_map` where `flatten` is sufficient"
/// let x = [1, 2, 3];
/// let y: Vec<_> = x.iter().map(|x| 2*x).collect();
/// ```
+ #[clippy::version = "1.52.0"]
pub MAP_IDENTITY,
complexity,
"using iterator.map(|x| x)"
/// // Good
/// let _ = "Hello".as_bytes().get(3);
/// ```
+ #[clippy::version = "1.52.0"]
pub BYTES_NTH,
style,
"replace `.bytes().nth()` with `.as_bytes().get()`"
/// let b = a.clone();
/// let c = a.clone();
/// ```
+ #[clippy::version = "1.52.0"]
pub IMPLICIT_CLONE,
pedantic,
"implicitly cloning a value by invoking a function on its dereferenced type"
/// let _ = some_vec.len();
/// let _ = &some_vec[..].len();
/// ```
+ #[clippy::version = "1.52.0"]
pub ITER_COUNT,
complexity,
"replace `.iter().count()` with `.len()`"
/// // use x
/// }
/// ```
+ #[clippy::version = "1.54.0"]
pub SUSPICIOUS_SPLITN,
correctness,
"checks for `.splitn(0, ..)` and `.splitn(1, ..)`"
/// // Good
/// let x: String = "x".repeat(10);
/// ```
+ #[clippy::version = "1.54.0"]
pub MANUAL_STR_REPEAT,
perf,
"manual implementation of `str::repeat`"
/// let (key, value) = _.split_once('=')?;
/// let value = _.split_once('=')?.1;
/// ```
+ #[clippy::version = "1.57.0"]
pub MANUAL_SPLIT_ONCE,
complexity,
"replace `.splitn(2, pat)` with `.split_once(pat)`"
/// ```
/// It will always be equal to `0`. Probably the author meant to clamp the value
/// between 0 and 100, but has erroneously swapped `min` and `max`.
+ #[clippy::version = "pre 1.29.0"]
pub MIN_MAX,
correctness,
"`min(_, max(_, _))` (or vice versa) with bounds clamping the result to a constant"
/// true
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub TOPLEVEL_REF_ARG,
style,
"an entire binding declared as `ref`, in a function argument or a `let` statement"
/// // Good
/// if x.is_nan() { }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub CMP_NAN,
correctness,
"comparisons to `NAN`, which will always return false, probably not intended"
/// if (y - 1.23f64).abs() < error_margin { }
/// if (y - x).abs() > error_margin { }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub FLOAT_CMP,
pedantic,
"using `==` or `!=` on float values instead of comparing difference with an epsilon"
/// # let y = String::from("foo");
/// if x == y {}
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub CMP_OWNED,
perf,
"creating owned instances for comparing with others, e.g., `x == \"foo\".to_string()`"
/// let a = x % 1;
/// let a = x % -1;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MODULO_ONE,
correctness,
"taking a number modulo +/-1, which can either panic/overflow or always returns 0"
/// let y = _x + 1; // Here we are using `_x`, even though it has a leading
/// // underscore. We should rename `_x` to `x`
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub USED_UNDERSCORE_BINDING,
pedantic,
"using a binding which is prefixed with an underscore"
/// ```rust,ignore
/// f() && g(); // We should write `if f() { g(); }`.
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub SHORT_CIRCUIT_STATEMENT,
complexity,
"using a short circuit boolean condition as a statement"
/// // Good
/// let a = std::ptr::null::<u32>();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub ZERO_PTR,
style,
"using `0 as *{const, mut} T`"
/// // let error_margin = std::f64::EPSILON;
/// if (x - ONE).abs() < error_margin { }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub FLOAT_CMP_CONST,
restriction,
"using `==` or `!=` on float constants instead of comparing difference with an epsilon"
/// Foo { .. } => {},
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub UNNEEDED_FIELD_PATTERN,
restriction,
"struct fields bound to a wildcard instead of using `..`"
/// // Good
/// fn bar(a: i32, _b: i32) {}
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub DUPLICATE_UNDERSCORE_ARGUMENT,
style,
"function arguments having names which only differ by an underscore"
/// let mut x = 3;
/// --x;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub DOUBLE_NEG,
style,
"`--x`, which is a double negation of `x` and not a pre-decrement as in C/C++"
/// // Good
/// let y = 0x1A9BACD;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MIXED_CASE_HEX_LITERALS,
style,
"hex literals whose letter digits are not consistently upper- or lowercased"
/// // Good
/// let y = 123832_i32;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub UNSEPARATED_LITERAL_SUFFIX,
restriction,
"literals whose suffix is not separated by an underscore"
/// ```
///
/// prints `83` (as `83 == 0o123` while `123 == 0o173`).
+ #[clippy::version = "pre 1.29.0"]
pub ZERO_PREFIXED_LITERAL,
complexity,
"integer literals starting with `0`"
/// }
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub BUILTIN_TYPE_SHADOW,
style,
"shadowing a builtin type"
/// y => (),
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub REDUNDANT_PATTERN,
style,
"using `name @ _` in a pattern"
/// _ => (),
/// }
/// ```
+ #[clippy::version = "1.40.0"]
pub UNNEEDED_WILDCARD_PATTERN,
complexity,
"tuple patterns with a wildcard pattern (`_`) is next to a rest pattern (`..`)"
/// }
/// # }
/// ```
+ #[clippy::version = "1.34.0"]
pub MISSING_CONST_FOR_FN,
nursery,
"Lint functions definitions that could be made `const fn`"
/// allowed-by-default lint for
/// public members, but has no way to enforce documentation of private items.
/// This lint fixes that.
+ #[clippy::version = "pre 1.29.0"]
pub MISSING_DOCS_IN_PRIVATE_ITEMS,
restriction,
"detects missing documentation for public and private members"
/// ```rust,ignore
/// use serde_json::Value as JsonValue;
/// ```
+ #[clippy::version = "1.55.0"]
pub MISSING_ENFORCED_IMPORT_RENAMES,
restriction,
"enforce import renames"
/// fn def_bar() {} // missing #[inline]
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MISSING_INLINE_IN_PUBLIC_ITEMS,
restriction,
"detects missing `#[inline]` attribute for public callables (functions, trait methods, methods...)"
/// stuff.rs
/// lib.rs
/// ```
+ #[clippy::version = "1.57.0"]
pub MOD_MODULE_FILES,
restriction,
"checks that module layout is consistent"
/// lib.rs
/// ```
+ #[clippy::version = "1.57.0"]
pub SELF_NAMED_MODULE_FILES,
restriction,
"checks that module layout is consistent"
/// ```rust
/// let x = -17 % 3;
/// ```
+ #[clippy::version = "1.42.0"]
pub MODULO_ARITHMETIC,
restriction,
"any modulo arithmetic statement"
/// ctrlc = "=3.1.0"
/// ansi_term = "=0.11.0"
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MULTIPLE_CRATE_VERSIONS,
cargo,
"multiple versions of the same crate being used"
/// let _: HashSet<Bad> = HashSet::new();
/// }
/// ```
+ #[clippy::version = "1.42.0"]
pub MUTABLE_KEY_TYPE,
suspicious,
"Check for mutable `Map`/`Set` key type"
/// # let mut y = 1;
/// let x = &mut &mut y;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MUT_MUT,
pedantic,
"usage of double-mut refs, e.g., `&mut &mut ...`"
/// let value = value_mutex.get_mut().unwrap();
/// *value += 1;
/// ```
+ #[clippy::version = "1.49.0"]
pub MUT_MUTEX_LOCK,
style,
"`&mut Mutex::lock` does unnecessary locking"
/// // Good
/// my_vec.push(&value)
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub UNNECESSARY_MUT_PASSED,
style,
"an argument passed as a mutable reference although the callee only demands an immutable reference"
/// fn take_a_mut_parameter(_: &mut u32) -> bool { unimplemented!() }
/// debug_assert!(take_a_mut_parameter(&mut 5));
/// ```
+ #[clippy::version = "1.40.0"]
pub DEBUG_ASSERT_WITH_MUT_CALL,
nursery,
"mutable arguments in `debug_assert{,_ne,_eq}!`"
/// # use std::sync::atomic::AtomicBool;
/// let x = AtomicBool::new(y);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MUTEX_ATOMIC,
perf,
"using a mutex where an atomic value could be used instead"
/// # use std::sync::atomic::AtomicUsize;
/// let x = AtomicUsize::new(0usize);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MUTEX_INTEGER,
nursery,
"using a mutex for an integer type"
/// }
/// }
/// ```
+ #[clippy::version = "1.47.0"]
pub NEEDLESS_ARBITRARY_SELF_TYPE,
complexity,
"type of `self` parameter is already by default `Self`"
/// let (x,y) = (true, false);
/// if x && !y {}
/// ```
+ #[clippy::version = "1.54.0"]
pub NEEDLESS_BITWISE_BOOL,
pedantic,
"Boolean expressions that use bitwise rather than lazy operators"
/// ```rust,ignore
/// !x
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NEEDLESS_BOOL,
complexity,
"if-statements with plain booleans in the then- and else-clause, e.g., `if p { true } else { false }`"
/// if x {}
/// if !y {}
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub BOOL_COMPARISON,
complexity,
"comparing a variable to a boolean, e.g., `if x == true` or `if x != true`"
/// let x: &i32 = &5;
/// fun(x);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NEEDLESS_BORROW,
style,
"taking a reference that is going to be automatically dereferenced"
/// // use `&x` here
/// }
/// ```
+ #[clippy::version = "1.54.0"]
pub REF_BINDING_TO_REFERENCE,
pedantic,
"`ref` binding to a reference"
/// let mut v = Vec::<String>::new();
/// let _ = v.iter_mut().filter(|a| a.is_empty());
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NEEDLESS_BORROWED_REFERENCE,
complexity,
"destructuring a reference and borrowing the inner value"
/// # break;
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NEEDLESS_CONTINUE,
pedantic,
"`continue` statements that can be replaced by a rearrangement of code"
/// println!("{}", elem);
/// }
/// ```
+ #[clippy::version = "1.53.0"]
pub NEEDLESS_FOR_EACH,
pedantic,
"using `for_each` where a `for` loop would be simpler"
/// let a = Some(&1);
/// let b = a;
/// ```
+ #[clippy::version = "1.57.0"]
pub NEEDLESS_OPTION_AS_DEREF,
complexity,
"no-op use of `deref` or `deref_mut` method to `Option`."
/// assert_eq!(v.len(), 42);
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NEEDLESS_PASS_BY_VALUE,
pedantic,
"functions taking arguments by value, but not consuming them in its body"
/// tr.and_then(|t| t.magic)
/// }
/// ```
+ #[clippy::version = "1.51.0"]
pub NEEDLESS_QUESTION_MARK,
complexity,
"Suggest `value.inner_option` instead of `Some(value.inner_option?)`. The same goes for `Result<T, E>`."
/// ..zero_point
/// };
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NEEDLESS_UPDATE,
complexity,
"using `Foo { ..base }` when there are no missing fields"
/// _ => false,
/// };
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NEG_CMP_OP_ON_PARTIAL_ORD,
complexity,
"The use of negated comparison operators on partially ordered types may produce confusing code."
/// ```ignore
/// x * -1
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NEG_MULTIPLY,
style,
"multiplying integers with `-1`"
/// }
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NEW_WITHOUT_DEFAULT,
style,
"`fn new() -> Self` method without `Default` implementation"
/// ```rust
/// 0;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NO_EFFECT,
complexity,
"statements with no effect"
/// ```rust,ignore
/// let _i_serve_no_purpose = 1;
/// ```
+ #[clippy::version = "1.58.0"]
pub NO_EFFECT_UNDERSCORE_BINDING,
pedantic,
"binding to `_` prefixed variable with no side-effect"
/// ```rust,ignore
/// compute_array()[0];
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub UNNECESSARY_OPERATION,
complexity,
"outer expressions with no effect"
/// STATIC_ATOM.store(9, SeqCst);
/// assert_eq!(STATIC_ATOM.load(SeqCst), 9); // use a `static` item to refer to the same instance
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub DECLARE_INTERIOR_MUTABLE_CONST,
style,
"declaring `const` with interior mutability"
/// STATIC_ATOM.store(9, SeqCst);
/// assert_eq!(STATIC_ATOM.load(SeqCst), 9); // use a `static` item to refer to the same instance
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub BORROW_INTERIOR_MUTABLE_CONST,
style,
"referencing `const` with interior mutability"
/// let checked_exp = something;
/// let checked_expr = something_else;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub SIMILAR_NAMES,
pedantic,
"similarly named items and bindings"
/// ```ignore
/// let (a, b, c, d, e, f, g) = (...);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MANY_SINGLE_CHAR_NAMES,
pedantic,
"too many single character bindings"
/// let ___1 = 1;
/// let __1___2 = 11;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub JUST_UNDERSCORES_AND_DIGITS,
style,
"unclear name"
/// let mut options = OpenOptions::new();
/// options.mode(0o644);
/// ```
+ #[clippy::version = "1.53.0"]
pub NON_OCTAL_UNIX_PERMISSIONS,
correctness,
"use of non-octal value to set unix file permissions, which will be translated into octal"
/// ```
/// Use thread-safe types like [`std::sync::Arc`](https://doc.rust-lang.org/std/sync/struct.Arc.html)
/// or specify correct bounds on generic type parameters (`T: Send`).
+ #[clippy::version = "1.57.0"]
pub NON_SEND_FIELDS_IN_SEND_TY,
suspicious,
"there is field that does not implement `Send` in a `Send` struct"
/// ```rust
/// vec![1, 2, 3];
/// ```
+ #[clippy::version = "1.55.0"]
pub NONSTANDARD_MACRO_BRACES,
nursery,
"check consistent use of braces in macro"
///
/// OpenOptions::new().read(true).truncate(true);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NONSENSICAL_OPEN_OPTIONS,
correctness,
"nonsensical combination of options for opening a file"
/// ```rust,no_run
/// let _ = env!("HOME");
/// ```
+ #[clippy::version = "1.43.0"]
pub OPTION_ENV_UNWRAP,
correctness,
"using `option_env!(...).unwrap()` to get environment variable"
/// y*y
/// }, |foo| foo);
/// ```
+ #[clippy::version = "1.47.0"]
pub OPTION_IF_LET_ELSE,
nursery,
"reimplementation of Option::map_or"
/// # let b = 2;
/// a + b < a;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub OVERFLOW_CHECK_CONDITIONAL,
complexity,
"overflow checks inspired by C which are likely to panic"
/// Err(String::from("error"))
/// }
/// ```
+ #[clippy::version = "1.48.0"]
pub PANIC_IN_RESULT_FN,
restriction,
"functions of type `Result<..>` that contain `panic!()`, `todo!()`, `unreachable()`, `unimplemented()` or assertion"
/// ```no_run
/// panic!("even with a good reason");
/// ```
+ #[clippy::version = "1.40.0"]
pub PANIC,
restriction,
"usage of the `panic!` macro"
/// ```no_run
/// unimplemented!();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub UNIMPLEMENTED,
restriction,
"`unimplemented!` should not be present in production code"
/// ```no_run
/// todo!();
/// ```
+ #[clippy::version = "1.40.0"]
pub TODO,
restriction,
"`todo!` should not be present in production code"
/// ```no_run
/// unreachable!();
/// ```
+ #[clippy::version = "1.40.0"]
pub UNREACHABLE,
restriction,
"usage of the `unreachable!` macro"
/// fn ne(&self, other: &Foo) -> bool { !(self == other) }
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub PARTIALEQ_NE_IMPL,
complexity,
"re-implementing `PartialEq::ne`"
/// // Better
/// fn foo(v: u32) {}
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub TRIVIALLY_COPY_PASS_BY_REF,
pedantic,
"functions taking small copyable arguments by reference"
/// // Good
/// fn foo(v: &TooLarge) {}
/// ```
+ #[clippy::version = "1.49.0"]
pub LARGE_TYPES_PASSED_BY_VALUE,
pedantic,
"functions taking large arguments by value"
/// x.push("bar");
/// assert_eq!(x, PathBuf::from("/foo/bar"));
/// ```
+ #[clippy::version = "1.36.0"]
pub PATH_BUF_PUSH_OVERWRITE,
nursery,
"calling `push` with file system root on `PathBuf` can overwrite it"
/// *a += b;
/// }
/// ```
+ #[clippy::version = "1.47.0"]
pub PATTERN_TYPE_MISMATCH,
restriction,
"type of pattern does not match the expression type"
/// ### Example
/// * `1 << 2 + 3` equals 32, while `(1 << 2) + 3` equals 7
/// * `-1i32.abs()` equals -1, while `(-1i32).abs()` equals 1
+ #[clippy::version = "pre 1.29.0"]
pub PRECEDENCE,
complexity,
"operations where precedence may be unclear"
/// // Good
/// fn foo(&[u32]) { .. }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub PTR_ARG,
style,
"fn arguments of the type `&Vec<...>` or `&String`, suggesting to use `&[...]` or `&str` instead, respectively"
/// ..
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub CMP_NULL,
style,
"comparing a pointer to a null pointer, suggesting to use `.is_null()` instead"
/// ```ignore
/// fn foo(&Foo) -> &mut Bar { .. }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MUT_FROM_REF,
correctness,
"fns that create mutable refs from immutable ref args"
/// // Good
/// unsafe { std::slice::from_raw_parts(NonNull::dangling().as_ptr(), 0); }
/// ```
+ #[clippy::version = "1.53.0"]
pub INVALID_NULL_PTR_USAGE,
correctness,
"invalid usage of a null pointer, suggesting `NonNull::dangling()` instead"
///
/// assert!(std::ptr::eq(a, b));
/// ```
+ #[clippy::version = "1.49.0"]
pub PTR_EQ,
style,
"use `std::ptr::eq` when comparing raw pointers"
/// ptr.add(offset);
/// }
/// ```
+ #[clippy::version = "1.30.0"]
pub PTR_OFFSET_WITH_CAST,
complexity,
"unneeded pointer offset cast"
/// ```ignore
/// option?;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub QUESTION_MARK,
style,
"checks for expressions that could be replaced by the question mark operator"
/// # let x = vec![1];
/// x.iter().enumerate();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub RANGE_ZIP_WITH_LEN,
complexity,
"zipping iterator with a range when `enumerate()` would do"
/// ```rust,ignore
/// for x..=y { .. }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub RANGE_PLUS_ONE,
pedantic,
"`x..(y+1)` reads better as `x..=y`"
/// ```rust,ignore
/// for x..y { .. }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub RANGE_MINUS_ONE,
pedantic,
"`x..=(y-1)` reads better as `x..y`"
/// let sub = &arr[1..3];
/// }
/// ```
+ #[clippy::version = "1.45.0"]
pub REVERSED_EMPTY_RANGES,
correctness,
"reversing the limits of range expressions, resulting in empty ranges"
///# let x = 6;
/// assert!((3..8).contains(&x));
/// ```
+ #[clippy::version = "1.49.0"]
pub MANUAL_RANGE_CONTAINS,
style,
"manually reimplementing {`Range`, `RangeInclusive`}`::contains`"
///
/// Path::new("/a/b").join("c").to_path_buf();
/// ```
+ #[clippy::version = "1.32.0"]
pub REDUNDANT_CLONE,
perf,
"`clone()` of an owned value that is going to be dropped immediately"
/// // Good
/// let a = 42
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub REDUNDANT_CLOSURE_CALL,
complexity,
"throwaway closures called in the expression they are defined"
/// print!("Moving on...");
/// }
/// ```
+ #[clippy::version = "1.50.0"]
pub REDUNDANT_ELSE,
pedantic,
"`else` branch that can be removed without changing semantics"
/// ```ignore
/// let foo = Foo { bar };
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub REDUNDANT_FIELD_NAMES,
style,
"checks for fields in struct literals where shorthands could be used"
/// pub fn internal_fn() { }
/// }
/// ```
+ #[clippy::version = "1.44.0"]
pub REDUNDANT_PUB_CRATE,
nursery,
"Using `pub(crate)` visibility on items that are not crate visible due to the visibility of the module that contains them."
/// x
/// }
/// ```
+ #[clippy::version = "1.51.0"]
pub REDUNDANT_SLICING,
complexity,
"redundant slicing of the whole range of a type"
/// const FOO: &[(&str, &str, fn(&Bar) -> bool)] = &[...]
/// static FOO: &[(&str, &str, fn(&Bar) -> bool)] = &[...]
/// ```
+ #[clippy::version = "1.37.0"]
pub REDUNDANT_STATIC_LIFETIMES,
style,
"Using explicit `'static` lifetime for constants or statics when elision rules would allow omitting them."
/// ```rust,ignore
/// let x: Option<&u32> = Some(&0u32);
/// ```
+ #[clippy::version = "1.49.0"]
pub REF_OPTION_REF,
pedantic,
"use `Option<&T>` instead of `&Option<&T>`"
/// let a = f(b);
/// let c = d;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub DEREF_ADDROF,
complexity,
"use of `*&` or `*&mut` in an expression"
/// # let point = Point(30, 20);
/// let x = point.0;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub REF_IN_DEREF,
complexity,
"Use of reference in auto dereference expression."
/// ```ignore
/// Regex::new("|")
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub INVALID_REGEX,
correctness,
"invalid regular expressions"
/// ```ignore
/// Regex::new("^foobar")
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub TRIVIAL_REGEX,
nursery,
"trivial regular expressions"
/// let x = String::from("hello world").clone();
/// }
/// ```
+ #[clippy::version = "1.47.0"]
pub REPEAT_ONCE,
complexity,
"using `.repeat(1)` instead of `String.clone()`, `str.to_string()` or `slice.to_vec()` "
/// String::new()
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub LET_AND_RETURN,
style,
"creating a let-binding and then immediately returning it like `let x = expr; x` at the end of a block"
/// x
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NEEDLESS_RETURN,
style,
"using a return statement like `return expr;` where an expression would suffice"
/// fn foo(&self) {}
/// }
/// ```
+ #[clippy::version = "1.57.0"]
pub SAME_NAME_METHOD,
restriction,
"two method with same name"
/// a.y = a.y;
/// }
/// ```
+ #[clippy::version = "1.48.0"]
pub SELF_ASSIGNMENT,
correctness,
"explicit self-assignment"
/// }
/// }
/// ```
+ #[clippy::version = "1.55.0"]
pub SELF_NAMED_CONSTRUCTORS,
style,
"method should not have the same name as the type it is implemented for"
/// println!("Hello world");
/// }
/// ```
+ #[clippy::version = "1.52.0"]
pub SEMICOLON_IF_NOTHING_RETURNED,
pedantic,
"add a semicolon if nothing is returned"
/// ### Example
/// Implementing `Visitor::visit_string` but not
/// `Visitor::visit_str`.
+ #[clippy::version = "pre 1.29.0"]
pub SERDE_API_MISUSE,
correctness,
"various things that will negatively affect your serde experience"
/// // Good
/// let y = &x; // use different variable name
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub SHADOW_SAME,
restriction,
"rebinding a name to itself, e.g., `let mut x = &mut x`"
/// let x = 2;
/// let y = x + 1;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub SHADOW_REUSE,
restriction,
"rebinding a name to an expression that re-uses the original value, e.g., `let x = x + 1`"
/// // Good
/// let w = z; // use different variable name
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub SHADOW_UNRELATED,
restriction,
"rebinding a name without even using the original value"
/// regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
/// }
/// ```
+ #[clippy::version = "1.43.0"]
pub SINGLE_COMPONENT_PATH_IMPORTS,
style,
"imports with single component path are redundant"
/// let mut y = [2u8; SIZE];
/// unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>() * SIZE) };
/// ```
+ #[clippy::version = "1.50.0"]
pub SIZE_OF_IN_ELEMENT_COUNT,
correctness,
"using `size_of::<T>` or `size_of_val::<T>` where a count of elements of `T` is expected"
/// let mut vec1 = vec![0; len];
/// let mut vec2 = vec![0; len];
/// ```
+ #[clippy::version = "1.32.0"]
pub SLOW_VECTOR_INITIALIZATION,
perf,
"slow vector initialization"
/// let mut vec = vec![2, 1, 3];
/// vec.sort_unstable();
/// ```
+ #[clippy::version = "1.47.0"]
pub STABLE_SORT_PRIMITIVE,
perf,
"use of sort() when sort_unstable() is equivalent"
/// x += ", World";
/// x.push_str(", World");
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub STRING_ADD_ASSIGN,
pedantic,
"using `x = x + ..` where x is a `String` instead of `push_str()`"
/// let x = "Hello".to_owned();
/// x + ", World";
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub STRING_ADD,
restriction,
"using `x + ..` where x is a `String` instead of `push_str()`"
/// // Good
/// let bs = b"a byte string";
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub STRING_LIT_AS_BYTES,
nursery,
"calling `as_bytes` on a string literal instead of using a byte string literal"
/// ```rust,should_panic
/// &"Ölkanne"[1..];
/// ```
+ #[clippy::version = "1.58.0"]
pub STRING_SLICE,
restriction,
"slicing a string"
/// ```rust
/// let _ = &"Hello World!"[6..11];
/// ```
+ #[clippy::version = "1.50.0"]
pub STRING_FROM_UTF8_AS_BYTES,
complexity,
"casting string slices to byte slices and back"
/// // example code which does not raise clippy warning
/// let _ = "str".to_owned();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub STR_TO_STRING,
restriction,
"using `to_string()` on a `&str`, which should be `to_owned()`"
/// let msg = String::from("Hello World");
/// let _ = msg.clone();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub STRING_TO_STRING,
restriction,
"using `to_string()` on a `String`, which should be `clone()`"
/// let cstring = CString::new("foo").expect("CString::new failed");
/// let len = cstring.as_bytes().len();
/// ```
+ #[clippy::version = "1.55.0"]
pub STRLEN_ON_C_STRINGS,
complexity,
"using `libc::strlen` on a `CString` or `CStr` value, while `as_bytes().len()` or `to_bytes().len()` respectively can be used instead"
/// }
/// }
/// ```
+ #[clippy::version = "1.50.0"]
pub SUSPICIOUS_OPERATION_GROUPINGS,
nursery,
"groupings of binary operations that look suspiciously like typos"
/// }
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub SUSPICIOUS_ARITHMETIC_IMPL,
suspicious,
"suspicious use of operators in impl of arithmetic trait"
/// }
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub SUSPICIOUS_OP_ASSIGN_IMPL,
suspicious,
"suspicious use of operators in impl of OpAssign trait"
/// let mut b = 2;
/// std::mem::swap(&mut a, &mut b);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MANUAL_SWAP,
complexity,
"manual swap of two variables"
/// # let mut b = 2;
/// std::mem::swap(&mut a, &mut b);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub ALMOST_SWAPPED,
correctness,
"`foo = bar; bar = foo` sequence"
/// second_string: String,
///}
/// ```
+ #[clippy::version = "1.41.0"]
pub TABS_IN_DOC_COMMENTS,
style,
"using tabs in doc comments is not recommended"
/// ```rust
/// (0, 0).0 = 1
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub TEMPORARY_ASSIGNMENT,
complexity,
"assignments to temporaries"
/// # let radix = 10;
/// let is_digit = c.is_digit(radix);
/// ```
+ #[clippy::version = "1.41.0"]
pub TO_DIGIT_IS_SOME,
style,
"`char.is_digit()` is clearer"
/// }
/// }
/// ```
+ #[clippy::version = "1.48.0"]
pub TO_STRING_IN_DISPLAY,
correctness,
"`to_string` method used while implementing `Display` trait"
/// last: [u32; 0],
/// }
/// ```
+ #[clippy::version = "1.58.0"]
pub TRAILING_EMPTY_ARRAY,
nursery,
"struct with a trailing zero-sized array but without `#[repr(C)]` or another `repr` attribute"
/// ```rust
/// pub fn foo<T>(t: T) where T: Copy + Clone {}
/// ```
+ #[clippy::version = "1.38.0"]
pub TYPE_REPETITION_IN_BOUNDS,
pedantic,
"Types are repeated unnecessary in trait bounds use `+` instead of using `T: _, T: _`"
/// ```rust
/// fn func<T>(arg: T) where T: Clone + Default {}
/// ```
+ #[clippy::version = "1.47.0"]
pub TRAIT_DUPLICATION_IN_BOUNDS,
pedantic,
"Check if the same trait bounds are specified twice during a function declaration"
/// ```ignore
/// let ptr: *const T = core::intrinsics::transmute('x')
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub WRONG_TRANSMUTE,
correctness,
"transmutes that are confusing at best, undefined behaviour at worst and always useless"
/// ```rust,ignore
/// core::intrinsics::transmute(t); // where the result type is the same as `t`'s
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub USELESS_TRANSMUTE,
nursery,
"transmutes that have the same to and from types or could be a cast/coercion"
/// # let p: *const [i32] = &[];
/// p as *const [u16];
/// ```
+ #[clippy::version = "1.47.0"]
pub TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS,
complexity,
"transmutes that could be a pointer cast"
/// core::intrinsics::transmute(t) // where the result type is the same as
/// // `*t` or `&t`'s
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub CROSSPOINTER_TRANSMUTE,
complexity,
"transmutes that have to or from types that are a pointer to the other"
/// // can be written:
/// let _: &T = &*p;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub TRANSMUTE_PTR_TO_REF,
complexity,
"transmutes from a pointer to a reference type"
/// // should be:
/// let _ = std::char::from_u32(x).unwrap();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub TRANSMUTE_INT_TO_CHAR,
complexity,
"transmutes from an integer to a `char`"
/// // should be:
/// let _ = std::str::from_utf8(b).unwrap();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub TRANSMUTE_BYTES_TO_STR,
complexity,
"transmutes from a `&[u8]` to a `&str`"
/// // should be:
/// let _: bool = x != 0;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub TRANSMUTE_INT_TO_BOOL,
complexity,
"transmutes from an integer to a `bool`"
/// // should be:
/// let _: f32 = f32::from_bits(1_u32);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub TRANSMUTE_INT_TO_FLOAT,
complexity,
"transmutes from an integer to a float"
/// // should be:
/// let _: u32 = 1f32.to_bits();
/// ```
+ #[clippy::version = "1.41.0"]
pub TRANSMUTE_FLOAT_TO_INT,
complexity,
"transmutes from a float to an integer"
/// // should be
/// let x: [u8; 8] = 0i64.to_ne_bytes();
/// ```
+ #[clippy::version = "1.58.0"]
pub TRANSMUTE_NUM_TO_BYTES,
complexity,
"transmutes from a number to an array of `u8`"
/// let _ = ptr as *const f32;
/// let _ = unsafe{ &*(&1u32 as *const u32 as *const f32) };
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub TRANSMUTE_PTR_TO_PTR,
pedantic,
"transmutes from a pointer to a pointer / a reference to a reference"
/// ```rust
/// vec![2_u16].into_iter().map(u32::from).collect::<Vec<_>>();
/// ```
+ #[clippy::version = "1.40.0"]
pub UNSOUND_COLLECTION_TRANSMUTE,
correctness,
"transmute between collections of layout-incompatible types"
/// ```rust
/// let null_ref: &u64 = unsafe { std::mem::transmute(0 as *const u64) };
/// ```
+ #[clippy::version = "1.35.0"]
pub TRANSMUTING_NULL,
correctness,
"transmutes from a null pointer to a reference, which is undefined behavior"
/// Ok(0)
/// }
/// ```
+ #[clippy::version = "1.38.0"]
pub TRY_ERR,
style,
"return errors explicitly rather than hiding them behind a `?`"
/// values: Vec<Foo>,
/// }
/// ```
+ #[clippy::version = "1.57.0"]
pub BOX_COLLECTION,
perf,
"usage of `Box<Vec<T>>`, vector elements are already on the heap"
/// values: Vec<i32>,
/// }
/// ```
+ #[clippy::version = "1.33.0"]
pub VEC_BOX,
complexity,
"usage of `Vec<Box<T>>` where T: Sized, vector elements are already on the heap"
/// Contents::None
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub OPTION_OPTION,
pedantic,
"usage of `Option<Option<T>>`"
/// # use std::collections::LinkedList;
/// let x: LinkedList<usize> = LinkedList::new();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub LINKEDLIST,
pedantic,
"usage of LinkedList, usually a vector is faster, or a more specialized data structure like a `VecDeque`"
/// ```rust,ignore
/// fn foo(bar: &T) { ... }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub BORROWED_BOX,
complexity,
"a borrow of a boxed type"
/// ```rust
/// fn foo(bar: &usize) {}
/// ```
+ #[clippy::version = "1.44.0"]
pub REDUNDANT_ALLOCATION,
perf,
"redundant allocation"
/// ```rust,ignore
/// fn foo(interned: Rc<str>) { ... }
/// ```
+ #[clippy::version = "1.48.0"]
pub RC_BUFFER,
restriction,
"shared ownership of a buffer type"
/// inner: Rc<Vec<Vec<Box<(u32, u32, u32, u32)>>>>,
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub TYPE_COMPLEXITY,
complexity,
"usage of very complex types that might be better factored into `type` definitions"
/// use std::cell::RefCell
/// fn foo(interned: Rc<RefCell<i32>>) { ... }
/// ```
+ #[clippy::version = "1.55.0"]
pub RC_MUTEX,
restriction,
"usage of `Rc<Mutex<T>>`"
/// // Safety: references are guaranteed to be non-null.
/// let ptr = unsafe { NonNull::new_unchecked(a) };
/// ```
+ #[clippy::version = "1.58.0"]
pub UNDOCUMENTED_UNSAFE_BLOCKS,
restriction,
"creating an unsafe block without explaining why it is safe"
/// std::mem::ManuallyDrop::drop(&mut std::mem::ManuallyDrop::new(S));
/// }
/// ```
+ #[clippy::version = "1.49.0"]
pub UNDROPPED_MANUALLY_DROPS,
correctness,
"use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value"
/// ### Example
/// You don't see it, but there may be a zero-width space or soft hyphen
/// someÂwhere in this text.
+ #[clippy::version = "1.49.0"]
pub INVISIBLE_CHARACTERS,
correctness,
"using an invisible character in a string literal, which is confusing"
/// ```rust
/// let x = String::from("\u{20ac}");
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NON_ASCII_LITERAL,
restriction,
"using any literal non-ASCII chars in a string literal instead of using the `\\u` escape"
/// ### Example
/// You may not see it, but "à"" and "à "" aren't the same string. The
/// former when escaped is actually `"a\u{300}"` while the latter is `"\u{e0}"`.
+ #[clippy::version = "pre 1.29.0"]
pub UNICODE_NOT_NFC,
pedantic,
"using a Unicode literal not in NFC normal form (see [Unicode tr15](http://www.unicode.org/reports/tr15/) for further information)"
/// // perform initialization with `remaining`
/// vec.set_len(...); // Safe to call `set_len()` on initialized part
/// ```
+ #[clippy::version = "1.58.0"]
pub UNINIT_VEC,
correctness,
"Vec with uninitialized data"
/// WithValue(x) => x.hash(&mut state),
/// }
/// ```
+ #[clippy::version = "1.58.0"]
pub UNIT_HASH,
correctness,
"hashing a unit value, which does nothing"
/// let mut twins = vec!((1, 1), (2, 2));
/// twins.sort_by_key(|x| { x.1; });
/// ```
+ #[clippy::version = "1.47.0"]
pub UNIT_RETURN_EXPECTING_ORD,
correctness,
"fn arguments of type Fn(...) -> Ord returning the unit type ()."
/// 1;
/// };
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub LET_UNIT_VALUE,
pedantic,
"creating a `let` binding to a value of unit type, which usually can't be used afterwards"
/// assert_eq!({ foo(); }, { bar(); });
/// ```
/// will always succeed
+ #[clippy::version = "pre 1.29.0"]
pub UNIT_CMP,
correctness,
"comparing unit values"
/// baz(a);
/// })
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub UNIT_ARG,
complexity,
"passing unit to a function"
/// // ...
/// }
/// ```
+ #[clippy::version = "1.44.0"]
pub FN_ADDRESS_COMPARISONS,
correctness,
"comparison with an address of a function item"
/// ...
/// }
/// ```
+ #[clippy::version = "1.44.0"]
pub VTABLE_ADDRESS_COMPARISONS,
correctness,
"comparison with an address of a trait vtable"
/// ```rust
/// use std::io;
/// ```
+ #[clippy::version = "1.53.0"]
pub UNNECESSARY_SELF_IMPORTS,
restriction,
"imports ending in `::{self}`, which can be omitted"
/// # let mut vec: Vec<A> = Vec::new();
/// vec.sort_by_key(|a| a.foo());
/// ```
+ #[clippy::version = "1.46.0"]
pub UNNECESSARY_SORT_BY,
complexity,
"Use of `Vec::sort_by` when `Vec::sort_by_key` or `Vec::sort` would be clearer"
/// }
/// }
/// ```
+ #[clippy::version = "1.50.0"]
pub UNNECESSARY_WRAPS,
pedantic,
"functions that only return `Ok` or `Some`"
/// if let Some(0 | 2) = Some(0) {}
/// }
/// ```
+ #[clippy::version = "1.46.0"]
pub UNNESTED_OR_PATTERNS,
pedantic,
"unnested or-patterns, e.g., `Foo(Bar) | Foo(Baz) instead of `Foo(Bar | Baz)`"
/// extern crate crossbeam;
/// use crossbeam::{spawn_unsafe as spawn};
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub UNSAFE_REMOVED_FROM_NAME,
style,
"`unsafe` removed from API names on import"
/// }
/// let number_future = async { get_random_number_improved() };
/// ```
+ #[clippy::version = "1.54.0"]
pub UNUSED_ASYNC,
pedantic,
"finds async functions with no await statements"
/// Ok(())
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub UNUSED_IO_AMOUNT,
correctness,
"unused written/read amount"
/// fn method() {}
/// }
/// ```
+ #[clippy::version = "1.40.0"]
pub UNUSED_SELF,
pedantic,
"methods that contain a `self` argument but don't use it"
/// ```rust
/// fn return_unit() {}
/// ```
+ #[clippy::version = "1.31.0"]
pub UNUSED_UNIT,
style,
"needless unit expression"
/// do_something_with(value)
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub UNNECESSARY_UNWRAP,
complexity,
"checks for calls of `unwrap[_err]()` that cannot fail"
/// ```
///
/// This code will always panic. The if condition should probably be inverted.
+ #[clippy::version = "pre 1.29.0"]
pub PANICKING_UNWRAP,
correctness,
"checks for calls of `unwrap[_err]()` that will always fail"
/// Ok(())
/// }
/// ```
+ #[clippy::version = "1.48.0"]
pub UNWRAP_IN_RESULT,
restriction,
"functions of type `Result<..>` or `Option`<...> that contain `expect()` or `unwrap()`"
/// ```rust
/// struct HttpResponse;
/// ```
+ #[clippy::version = "1.51.0"]
pub UPPER_CASE_ACRONYMS,
style,
"capitalized acronyms are against the naming convention"
/// }
/// }
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub USE_SELF,
nursery,
"unnecessary structure name repetition whereas `Self` is applicable"
/// // Good
/// let s: String = format!("hello");
/// ```
+ #[clippy::version = "1.45.0"]
pub USELESS_CONVERSION,
complexity,
"calls to `Into`, `TryInto`, `From`, `TryFrom`, or `IntoIter` which perform useless conversions to the same type"
/// // Good
/// foo(&[1, 2]);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub USELESS_VEC,
perf,
"useless `vec!`"
/// ```rust
/// let v = vec![0];
/// ```
+ #[clippy::version = "1.51.0"]
pub VEC_INIT_THEN_PUSH,
perf,
"`push` immediately after `Vec` creation"
/// ```rust
/// vec!(1, 2, 3, 4, 5).resize(0, 5)
/// ```
+ #[clippy::version = "1.46.0"]
pub VEC_RESIZE_TO_ZERO,
correctness,
"emptying a vector with `resize(0, an_int)` instead of `clear()` is probably an argument inversion mistake"
/// # use std::fs;
/// let mut bytes = fs::read("foo.txt").unwrap();
/// ```
+ #[clippy::version = "1.44.0"]
pub VERBOSE_FILE_READS,
restriction,
"use of `File::read_to_end` or `File::read_to_string`"
/// [dependencies]
/// regex = "*"
/// ```
+ #[clippy::version = "1.32.0"]
pub WILDCARD_DEPENDENCIES,
cargo,
"wildcard dependencies being used"
/// use std::cmp::Ordering;
/// foo(Ordering::Less)
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub ENUM_GLOB_USE,
pedantic,
"use items that import all variants of an enum"
///
/// foo();
/// ```
+ #[clippy::version = "1.43.0"]
pub WILDCARD_IMPORTS,
pedantic,
"lint `use _::*` statements"
/// // Good
/// println!();
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub PRINTLN_EMPTY_STRING,
style,
"using `println!(\"\")` with an empty string"
/// # let name = "World";
/// println!("Hello {}!", name);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub PRINT_WITH_NEWLINE,
style,
"using `print!()` with a format string that ends in a single newline"
/// ```rust
/// println!("Hello world!");
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub PRINT_STDOUT,
restriction,
"printing on stdout"
/// ```rust
/// eprintln!("Hello world!");
/// ```
+ #[clippy::version = "1.50.0"]
pub PRINT_STDERR,
restriction,
"printing on stderr"
/// # let foo = "bar";
/// println!("{:?}", foo);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub USE_DEBUG,
restriction,
"use of `Debug`-based formatting"
/// ```rust
/// println!("foo");
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub PRINT_LITERAL,
style,
"printing a literal with a format string"
/// // Good
/// writeln!(buf);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub WRITELN_EMPTY_STRING,
style,
"using `writeln!(buf, \"\")` with an empty string"
/// // Good
/// writeln!(buf, "Hello {}!", name);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub WRITE_WITH_NEWLINE,
style,
"using `write!()` with a format string that ends in a single newline"
/// // Good
/// writeln!(buf, "foo");
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub WRITE_LITERAL,
style,
"writing a literal with a format string"
/// // Good
/// let nan = f32::NAN;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub ZERO_DIVIDED_BY_ZERO,
complexity,
"usage of `0.0 / 0.0` to obtain NaN instead of `f32::NAN` or `f64::NAN`"
/// todo!();
/// }
/// ```
+ #[clippy::version = "1.50.0"]
pub ZERO_SIZED_MAP_VALUES,
pedantic,
"usage of map with zero-sized value type"