Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wooster0 opened this issue Oct 18, 2021 · 2 comments
Closed
Labels
A-lint Area: New lints

Comments

@wooster0
Copy link

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);
@wooster0 wooster0 added the A-lint Area: New lints label Oct 18, 2021
@alex-700
Copy link
Contributor

alex-700 commented Oct 18, 2021

@r00ster91 there is a long story about RFC-2011. From the clippy side you can see #641 and #2090. IMHO, nothing happened to change the decision from #2090.

@wooster0
Copy link
Author

Ah, so the ultimate goal would be to deprecate assert_eq and assert_ne. I see. I agree with that decision! So the relevant issue here would be rust-lang/rust#44838.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

2 participants