Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tcullum-gpsw opened this issue Dec 31, 2018 · 2 comments · Fixed by #65552
Closed

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

tcullum-gpsw opened this issue Dec 31, 2018 · 2 comments · Fixed by #65552
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tcullum-gpsw
Copy link

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"

@tcullum-gpsw tcullum-gpsw changed the title Error help msg when attempting usage of ~ as unary operator Error help msg when attempting usage of ~ as unary operator incorrect Dec 31, 2018
@tcullum-gpsw tcullum-gpsw changed the title Error help msg when attempting usage of ~ as unary operator incorrect Error help msg when attempting usage of ~ as unary operator misleading Dec 31, 2018
@nagisa
Copy link
Member

nagisa commented Jan 1, 2019

~ is referred to as “bitwise not”, “binary complement” and “bitwise negation” among many other names, so the current diagnostic is valid. Not sure where the confusion might arise here, because “bitwise” implies that the operation is… well… bitwise.

@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 2, 2019
@mark-i-m
Copy link
Member

mark-i-m commented Jan 2, 2019

bitwise not would be my preferred phrasing...

@estebank estebank added D-papercut Diagnostics: An error or lint that needs small tweaks. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 10, 2019
Centril added a commit to Centril/rust that referenced this issue Oct 18, 2019
Clarify diagnostics when using `~` as a unary op

It seems we prefer `bitwise not` to `bitwise negation`.
Fixes rust-lang#57239

r? @estebank
tmandry added a commit to tmandry/rust that referenced this issue Oct 18, 2019
Clarify diagnostics when using `~` as a unary op

It seems we prefer `bitwise not` to `bitwise negation`.
Fixes rust-lang#57239

r? @estebank
@bors bors closed this as completed in 3850408 Oct 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants