Skip to content

Suggest ! for bitwise negation when encountering a ~ #41679

Closed
@bstrie

Description

@bstrie

Here's a program:

fn main() {
    let x = ~1;
}

Its output:

error: expected expression, found `~`
 --> <anon>:2:13
  |
2 |     let x = ~1;
  |             ^

error: aborting due to previous error

Given that this is our only deviation from C-style bitwise operator syntax, it would be nice to have a note of some kind to suggest ! here.

Ideally the note would only appear when the ~ looks like it's being applied as a unary operator on a numeric type, but if that would require too much machinery then something simpler will suffice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions