Skip to content

Provide auto-fix suggestion for triple equals #75312

Closed
@clarfonthey

Description

@clarfonthey

Been working in JavaScript a lot lately and find myself accidentally typing this a lot. It would be nice to automatically detect this and offer a proper fix. Lots of languages use this syntax in addition to JavaScript so it seems like a reasonable error to make.

Playground example below.

#![feature(test)]
use std::hint::black_box;
fn main() {
    if 1 === black_box(1) {
        println!("yup!");
    } else if 2 !== black_box(2) {
        println!("nope!");
    }
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error: expected expression, found `=`
 --> src/main.rs:4:12
  |
4 |     if 1 === black_box(1) {
  |            ^ expected expression

warning: unused import: `std::hint::black_box`
 --> src/main.rs:2:5
  |
2 | use std::hint::black_box;
  |     ^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error: aborting due to previous error; 1 warning emitted

error: could not compile `playground`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.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