Skip to content

document that ! does bitwise and logical negation - #162668

Open
evan-dickinson wants to merge 1 commit into
rust-lang:mainfrom
evan-dickinson:bitwise-not
Open

document that ! does bitwise and logical negation#162668
evan-dickinson wants to merge 1 commit into
rust-lang:mainfrom
evan-dickinson:bitwise-not

Conversation

@evan-dickinson

Copy link
Copy Markdown

The documentation summary for core::ops::Not says that it performs
logical negation. That's misleading because it also performs bitwise
negation on integers. Since C has separate operators for logical and
bitwise negation, this could lead a C programmer to look
elsewhere for Rust's equivalent of ~.

I also updated the documentation for Not::not() to clarify the meaning of logical not vs bitwise not.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 11, 2026
Comment on lines +1 to +2
/// The unary negation operator `!`. It performs either logical or bitwise negation,
/// depending on the type.

@evan-dickinson evan-dickinson Sep 11, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a little unfortunate that this page introduces the concept of logical vs bitwise negation at the top, but you have to scroll down to see the examples of what that means. But this is consistent with the other examples in std::ops. The trait-level documentation demonstrates using the trait with a custom type, and the trait functions demonstrate using the trait with built-in types.

IMO, it would be more useful to have the first examples of these traits show them with built-in types. But I'd only want to take that on if I had buy-in from maintainers

View changes since the review

@evan-dickinson
evan-dickinson marked this pull request as ready for review September 12, 2026 00:00
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 12, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 12, 2026
@rustbot

rustbot commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @JohnTitor (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from Darksonn, JohnTitor, Mark-Simulacrum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants