Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions library/core/src/ops/bit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// The unary logical negation operator `!`.
/// The unary negation operator `!`. It performs either logical or bitwise negation,
/// depending on the type.
Comment on lines +1 to +2

@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

///
/// # Examples
///
Expand Down Expand Up @@ -37,15 +38,23 @@ pub const trait Not {
#[stable(feature = "rust1", since = "1.0.0")]
type Output;

/// Performs the unary `!` operation.
/// Performs the unary `!` operation using logical or bitwise negation.
///
/// # Examples
///
/// ```
/// // Logical negation changes between true and false:
/// assert_eq!(!true, false);
/// assert_eq!(!false, true);
///
/// // Bitwise negation changes between 0 and 1 in the binary
/// // representation of integers:
/// assert_eq!(!1u8, 254);
/// assert_eq!(!0u8, 255);
///
/// // The same examples, represented in binary:
/// assert_eq!(!0b0000_0001u8, 0b1111_1110);
/// assert_eq!(!0b0000_0000u8, 0b1111_1111);
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
Loading