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

Add lints to encourage use of specialized assert macros #13252

Open
Reisz opened this issue Aug 11, 2024 · 2 comments · May be fixed by #13333
Open

Add lints to encourage use of specialized assert macros #13252

Reisz opened this issue Aug 11, 2024 · 2 comments · May be fixed by #13333
Assignees
Labels
A-lint Area: New lints

Comments

@Reisz
Copy link

Reisz commented Aug 11, 2024

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

  • The specialized asserts provide more info in their error messages

Drawbacks

No response

Example

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

Could be written as:

assert_eq!(fib(6), 8);
@Reisz Reisz added the A-lint Area: New lints label Aug 11, 2024
@nyurik
Copy link
Contributor

nyurik commented Sep 1, 2024

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
Copy link
Contributor

nyurik commented Sep 2, 2024

@rustbot claim

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

Successfully merging a pull request may close this issue.

2 participants