Skip to content

Incorrect auto-fix: comparison to false breaks #10291

Closed
@black-puppydog

Description

@black-puppydog

I just stumbled over this and think the test cases specify the wrong behaviour.
This line:

assert_eq!("a".is_empty(), false);

Gets turned into this:

assert!("a".is_empty());

But these are opposite asserts, so this will break the test.

The same applies to all the other calls to assert_eq!(..., false) and assert_neq!(..., true) of course.

Edit: sorry for the lack of template, I created this from the GH blame view which seems so sidestep that.

Minimal Reproducer

fn main() {
    println!("Hello, world!");
}

#[cfg(test)]
mod test {
    #[test]
    fn assert_correctly_transformed() {
        let must_be_false = false;

        assert_eq!(must_be_false, false);
    }
}

Expected:

        assert!(!must_be_false);

Observed:

        assert!(must_be_false);

(note the lack of !)

clippy 0.1.69 (658fad6 2023-02-03)

This does NOT happen on stable (yet) since the auto-fix was only introduced recently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions