Skip to content

Consider warning by default for foo == bar; statements #38224

Closed
@crumblingstatue

Description

@crumblingstatue

One can make a mistake where they mistype = to ==.

Consider the following code:

fn main() {
    let mut a = 10;
    println!("A is {}", a);
    if 1 == 2 {
        a = 20;
    } else {
        a == 30; // Oops, meant assignment
    }
    println!("A is now {}", a); // Still 10
}

No warning is produced for this code.

I'd argue that this is a common enough mistake to justify warning by default for it.

If the user explicitly wants to do this operation for side effects or whatever, they can do let _ = a == b;, similarly to the explicit version for #[must_use] types.

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