Skip to content

Detect redundant always successful assert_eq! #8567

Open
@repi

Description

@repi

What it does

Detect if assert_eq! always returns succeeds because the same expression is on the left and right side, such as with assert_eq!(a,a).

These type of cases can happen when refactoring and search'n'replacing code, for example we've recently saw a case of this recently:

   assert_eq!(mem::size_of::<usize>(), mem::size_of::<usize>());

It would however be important that it only lints on the expressions being exactly identical, so if using a type alias in the above example that should not trigger this lint, example:

   type MyType = usize;
   assert_eq!(mem::size_of::<usize>(), mem::size_of::<MyType>());

Lint Name

redundant_assert

Category

pedantic

Advantage

Keeping an assert that has no effect is a code smell and negative value as can leave a false sense of safety in tests / coverage and is additional cognitive overhead without any positive effects.

Drawbacks

Likely none.

Probably not that common occurrence, but does happen.

Example

assert_eq!(mem::size_of::<usize>(), mem::size_of::<usize>());

Assert should simply be removed as it has no effect.

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