Skip to content

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

Open
@matthiaskrgr

Description

@matthiaskrgr
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions