rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.28k stars 1.52k forks source link

Add lints to encourage use of specialized assert macros #13252

Open Reisz opened 1 month ago

Reisz commented 1 month ago

What it does

Detect assert!(a == b) and assert!(a != b) and suggest using assert_eq! or assert_ne! respectively.

Should probably apply to debug_assert! as well.

Advantage

Drawbacks

No response

Example

assert!(fib(6) == 8);

Could be written as:

assert_eq!(fib(6), 8);
nyurik commented 2 weeks ago

I wonder if we should extend the bool_assert_comparison lint.

The description actually matches what is being proposed:

This lint warns about boolean comparisons in assert-like macros.

nyurik commented 2 weeks ago

@rustbot claim