Programming Search⌘K

Rust lints, page 5 of 5

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

Checks for usage of Debug formatting. use_debug

The purpose of this lint is to catch debugging remnants. The purpose of the Debug trait is to facilitate debugging Rust code, and no guarantees are made about its output. It should not be used in user-facing output. Clippy puts this lint in the restriction group, at the level allow.

Code
use_debug
Severity
allow

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

Detects format!-style macros (e.g. format!, println!, write!) where an argument is passed with an explicit & but the value is already a reference, resulting in a double reference (e.g. &&T). useless_borrows_in_formatting

The extra & is redundant and can make the code less clear. Format macros take references to the arguments internally, so passing &x when x is already a reference produces a double reference. The compiler is currently unable to optimize double references, which results in about 6% degradation per call. Clippy puts this lint in the perf group, at the level warn.

Code
useless_borrows_in_formatting
Severity
warn
Since
1.97.0

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

Checks for the use of format!("string literal with no argument") and format!("{}", foo) where foo is a string. useless_format

There is no point of doing that. format!("foo") can be replaced by "foo".to_owned() if you really need a String. The even worse &format!("foo") is often encountered in the wild. format!("{}", foo) can be replaced by foo.clone() if foo: String or foo.to_owned() if foo: &str. Clippy puts this lint in the complexity group, at the level warn.

Code
useless_format
Severity
warn

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

Checks for NonZero*::new_unchecked() being used in a const context. useless_nonzero_new_unchecked

Using NonZero*::new_unchecked() is an unsafe function and requires an unsafe context. When used in a context evaluated at compilation time, NonZero*::new().unwrap() will provide the same result with identical runtime performances while not requiring unsafe. Clippy puts this lint in the complexity group, at the level warn.

Code
useless_nonzero_new_unchecked
Severity
warn
Since
1.86.0

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

This lint warns when volatile load/store operations (write_volatile/read_volatile) are applied to composite types. volatile_composites

Volatile operations are typically used with memory mapped IO devices, where the precise number and ordering of load and store instructions is important because they can have side effects. This is well defined for primitive types like u32, but less well defined for structures and other composite types. In practice it’s implementation defined, and the behavior can be rustc-version dependent. Clippy puts this lint in the nursery group, at the level allow.

Code
volatile_composites
Severity
allow
Since
1.92.0

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

Checks for methods with certain name prefixes or suffixes, and which do not adhere to standard conventions regarding how self is taken. wrong_self_convention

The actual rules are: Consistency breeds readability. If you follow the conventions, your users won’t be surprised that they, e.g., need to supply a mutable reference to a as_.. function. Clippy puts this lint in the style group, at the level warn.

Code
wrong_self_convention
Severity
warn

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

Checks for array or vec initializations which contain an expression with side effects, but which have a repeat count of zero. zero_repeat_side_effects

Such an initialization, despite having a repeat length of 0, will still call the inner function. This may not be obvious and as such there may be unintended side effects in code. Clippy puts this lint in the suspicious group, at the level warn.

Code
zero_repeat_side_effects
Severity
warn
Since
1.79.0

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

Looks for code that spawns a process but never calls wait() on the child. zombie_processes

As explained in the standard library documentation, calling wait() is necessary on Unix platforms to properly release all OS resources associated with the process. Not doing so will effectively leak process IDs and/or other limited global resources, which can eventually lead to resource exhaustion, so it’s recommended to call wait() in long-running applications. Such processes are called “zombie processes”. Clippy puts this lint in the suspicious group, at the level warn.

Code
zombie_processes
Severity
warn
Since
1.83.0

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