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

assert! on == should be assert_eq! #12112

Closed
Apanatshka opened this issue Jan 8, 2024 · 2 comments
Closed

assert! on == should be assert_eq! #12112

Apanatshka opened this issue Jan 8, 2024 · 2 comments
Labels
A-lint Area: New lints

Comments

@Apanatshka
Copy link

What it does

  1. Find uses of assert! on the result of std::cmp::PartialEq::eq, suggest using assert_eq!.
  2. Do the same for debug_assert_eq!.

Advantage

An assertion failure can output a more useful message.

Drawbacks

No response

Example

assert!(
    self.some_method()
        == local_value
            .get_other_information(self.complex.expression[0], this.is.long),
    "The some_method result must be in sync with the other information."
);

Could be written as:

assert_eq!(
    self.some_method(),
    local_value.get_other_information(self.complex.expression[0], this.is.long),
    "The some_method result must be in sync with the other information."
);
@Apanatshka Apanatshka added the A-lint Area: New lints label Jan 8, 2024
@nicklimmm
Copy link

The lint for the above is deprecated from #2156.

From rust-lang/rust#44838, seems like we are heading towards a better assert! macro with better messages.

@Apanatshka
Copy link
Author

Apanatshka commented Jan 9, 2024

I was unaware of the planned changes, happy to hear that things will become better automatically :)

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