Skip to content

Replace {assert, debug_assert} using == or != by the _eq or _ne variants #7837

Closed
@ghost

Description

What it does

It checks for asserts like assert!(1 == 1); and suggests to replace it with assert_eq!(1, 1);.
As far as I know, this is more idiomatic.

Categories (optional)

  • Kind: most likely clippy::style or maybe clippy::complexity.

The advantage is idiomacy and consistency/consistent style.
It can also improve readability and the _eq/_ne variants make it much easier to search for specific kind of asserts (no regex for example needed).

Drawbacks

None.

Example

assert!(1 == 1);
assert!(5 != 10);
debug_assert!(1 == 1);
debug_assert!(5 != 10);

Could be written as:

assert_eq!(1, 1);
assert_ne!(5, 10);
debug_assert_eq!(1, 1);
debug_assert_ne!(5, 10);

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions