Clippy lints / Nursery
Clippy lint · Nursery · checked with Clippy 0.1.99
clippy::debug_assert_with_mut_call: Checks for function/method calls with a mutable parameter in debug_assert!, debug_assert_eq! and debug_assert_ne! macros
What it meansChecks for function/method calls with a mutable parameter in debug_assert!, debug_assert_eq! and debug_assert_ne! macros. It is in the nursery group and off by default.
Does it matter?
In release builds debug_assert! macros are optimized out by the compiler. Therefore mutating something in a debug_assert! macro results in different behavior between a release and debug build.
New lints still being finished. Off by default and may have false positives.
How to fix it
Clippy does not fix this one automatically. Change the code by hand:
Flagged
debug_assert_eq!(vec![3].pop(), Some(3));
// or
debug_assert!(takes_a_mut_parameter(&mut x));
Turn it off, or on
It is off by default. To use it, set it to warn or deny:
Whole crate (Cargo.toml)
[lints.clippy]
debug_assert_with_mut_call = "warn"In code
#![warn(clippy::debug_assert_with_mut_call)]One run
cargo clippy -- -W clippy::debug-assert-with-mut-callThe [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 function/method calls with a mutable
parameter in debug_assert!, debug_assert_eq! and debug_assert_ne! macros.
Why is this bad?
In release builds debug_assert! macros are optimized out by the
compiler.
Therefore mutating something in a debug_assert! macro results in different behavior
between a release and debug build.
Example
debug_assert_eq!(vec![3].pop(), Some(3));
// or
debug_assert!(takes_a_mut_parameter(&mut x));
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- redundant_cloneChecks for a redundant clone() (and its relatives) which clones an owned value that is going to be dropped without further use
- clear_with_drain`drain` used to clear a `Vec`
- coerce_container_to_anyProtects against unintended coercion of references to container types to &dyn Any when the container type dereferences to a dyn Any which could be directly referenced instead
- collection_is_never_readChecks for collections that are never queried
- derive_partial_eq_without_eqChecks for types that derive PartialEq and could implement Eq
- doc_link_codecode link adjacent to code text
- empty_enumsChecks for enums with no variants, which therefore are uninhabited types (cannot be instantiated). As of this writing, the never_type is still a nightly-only experimental API. Therefore, this lint is only triggered if #![feature(never_type)] is enabled
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::redundant_cloneChecks for a redundant clone() (and its relatives) which clones an owned value that is going to be dropped without further useRead it next →Did this answer your question?