Clippy lints / Style
Clippy lint · Style · checked with Clippy 0.1.99
clippy::assertions_on_constants: Checks for assert!(true) and assert!(false) calls
What it meansChecks for assert!(true) and assert!(false) calls. It is in the style group and warns by default.
Does it matter?
Will be optimized out by the compiler or should probably be replaced by a panic!() or unreachable!()
Code that works but is not idiomatic Rust. Warns by default.
How to fix it
Clippy does not fix this one automatically. Change the code by hand:
Flagged
assert!(false)
assert!(true)
const B: bool = false;
assert!(B)
Turn it off, or on
Allow it where it does not fit your code, as narrowly as you can:
On one item
#[allow(clippy::assertions_on_constants)]
fn my_function() { /* ... */ }Whole crate (Cargo.toml)
[lints.clippy]
assertions_on_constants = "allow"One run
cargo clippy -- -A clippy::assertions-on-constantsThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Clippy's own documentation
What it does
Checks for assert!(true) and assert!(false) calls.
Why is this bad?
Will be optimized out by the compiler or should probably be replaced by a
panic!() or unreachable!()
Example
assert!(false)
assert!(true)
const B: bool = false;
assert!(B)
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- needless_returnunneeded `return` statement
- new_without_defaultChecks for public types with a pub fn new() -> Self method and no implementation of Default
- len_zeroChecks for getting the length of something via .len() just to compare to zero, and suggests using .is_empty() where applicable
- assign_op_patternmanual implementation of an assign operation
- blocks_in_conditionsChecks for if and match conditions that use blocks containing an expression, statements or conditions that use closures with blocks
- bool_assert_comparisonused `assert_eq!` with a literal bool
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::needless_returnunneeded `return` statementRead it next →Did this answer your question?