Skip to content

New lint idea: suggest ^ when comparing bools #4983

Closed
@mgr-inz-rafal

Description

@mgr-inz-rafal

Hello,
During the review process of my recent PR there's been an idea to create a new lint for suggesting the usage of XOR when comparing bools, like so:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b5bbd3c8e28e981aa80e02a372f242e9

I'd like to work on it, but before I start let me get your opinion. Is it worth implementing? Are the other similar "optimizations" that can be included in such a lint come to your mind?

Any ideas are appreciated.

Original comment:

Wait, these are bools. So we could use a XOR here

                            if lhs_negative ^ rhs_negative;

Originally posted by @flip1995 in https://github.com/_render_node/MDIzOlB1bGxSZXF1ZXN0UmV2aWV3VGhyZWFkMjIwMTAzMDk5OnYy/pull_request_review_threads/discussion

Alternative link: #4867 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions