Summary
As of #11966, assertions_on_constants does not trigger for const _: () = assert!(expr).
In recent Rust versions, this can be more nicely written as const { assert!(expr) }.
IMO assertions in const blocks should be exempted from assertions_on_constants, because generally their entire purpose is to be evaluated at compile time.
Lint Name
assertions_on_constants
Reproducer
I tried this code:
pub fn foo() {
const { assert!(c_int::BITS <= usize::BITS) }
}
I saw this happen:
warning: `assert!(true)` will be optimized out by the compiler
|
39 | const { assert!(c_int::BITS <= usize::BITS) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: remove it
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants
= note: `#[warn(clippy::assertions_on_constants)]` on by default
I expected to see this happen:
No warnings.
Version
rustc 1.80.0-nightly (36153f1a4 2024-05-24)
binary: rustc
commit-hash: 36153f1a4e3162f0a143c7b3e468ecb3beb0008e
commit-date: 2024-05-24
host: aarch64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6
Additional Labels
No response
Summary
As of #11966,
assertions_on_constantsdoes not trigger forconst _: () = assert!(expr).In recent Rust versions, this can be more nicely written as
const { assert!(expr) }.IMO assertions in
constblocks should be exempted fromassertions_on_constants, because generally their entire purpose is to be evaluated at compile time.Lint Name
assertions_on_constants
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
No warnings.
Version
Additional Labels
No response