Skip to content

Error help msg when attempting usage of ~ as unary operator misleading #57239

Closed
@tcullum-gpsw

Description

@tcullum-gpsw

I find the error message confusing and possibly incorrect when attempting to use ~ as a unary operator:

In current Rust stable and nightly, I get:

error: `~` cannot be used as a unary operator
 --> src/main.rs:5:11
  |
5 |     num = ~num + 1;
  |           ^ help: use `!` to perform bitwise negation

The "help" is misleading because it is suggesting using ! to "perform bitwise negation." But this is not really what ~ performs. NEG and NOT are two separate instructions which perform different things. I think this message would be best changed to "perform bitwise NOT" or "perform bitwise one's complement"

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.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