Skip to content

diagnostics: suggets assert_eq!() instead of assert!() where appropriate #57507

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

Open
matthiaskrgr opened this issue Jan 11, 2019 · 0 comments
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jan 11, 2019

fn main() {
    let x = 3;
    assert!(x, 3);
}

This currently gives an error like so:

error[E0308]: mismatched types
 --> src/main.rs:3:5
  |
3 |     assert!(x, 3);
  |     ^^^^^^^^^^^^^^ expected bool, found integer
  |
  = note: expected type `bool`
             found type `{integer}`

error: aborting due to previous error

If arguments 1 and 2 are the same type, it would be great if we could instead suggest using assert_eq! instead (preferably with rustfix applicable hint)!

Alternatively we could suggest transforming x, 3 to x == 3 but I guess assert_eq!() is more idiomatic.

@Centril Centril added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 11, 2019
@estebank estebank added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 26, 2019
@estebank estebank added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Oct 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants