Skip to content

unit_cmp: special handling of assert_eq!(Option.unwrap(), ()); #4661

Open
@matthiaskrgr

Description

@matthiaskrgr
pub fn main() {
    let x: Option<()> = Some(());
    assert_eq!(x.unwrap(), ());
}

Clippy warns here ``assert_eq of unit values detected. This will always succeed, however this code will actually check and panic if x is None.

Can we suggest to replace it with
assert!(x.is_some()) in this case?

Found in cargo codebase of cargo.

clippy 0.0.212 (5cb9833 2019-10-08)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesL-suggestionLint: Improving, adding or fixing lint suggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions