Repository navigation
document that ! does bitwise and logical negation - #162668
Conversation
| /// The unary negation operator `!`. It performs either logical or bitwise negation, | ||
| /// depending on the type. |
There was a problem hiding this comment.
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
|
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:
|
…Titor document that `!` does bitwise and logical negation 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.
…uwer Rollup of 6 pull requests Successful merges: - #163104 ([debuginfo] Emit `usize` and `isize` as typedefs) - #164488 (Don't try to skip anything in `Skip::advance_by(0)`) - #164578 (Don't ignore unknown LLVM diagnostics) - #164611 (Improve bit permutation codegen) - #162668 (document that `!` does bitwise and logical negation) - #164264 (lint: suggest `fXX::is_nan` for unsuffixed NaN comparisons)
…Titor document that `!` does bitwise and logical negation 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.
…uwer Rollup of 14 pull requests Successful merges: - #163575 (core: Add examples and assembly tests for `abort_immediate`) - #163664 (Add new `RUSTC_BOOTSTRAP=-allow-unstable-compiler-flags` mode for testing stable compiler behavior in UI tests) - #163104 ([debuginfo] Emit `usize` and `isize` as typedefs) - #163338 (MIR move elimination [4/6]: MoveElimination) - #163701 (add ReadDir::dir to get the directory handle of the underlying directory) - #164488 (Don't try to skip anything in `Skip::advance_by(0)`) - #164578 (Don't ignore unknown LLVM diagnostics) - #164611 (Improve bit permutation codegen) - #164612 (std: Combine `is_powerpc64_feature_detected` into `is_powerpc_feature_detected`) - #162668 (document that `!` does bitwise and logical negation) - #164264 (lint: suggest `fXX::is_nan` for unsuffixed NaN comparisons) - #164509 (layout invariant: turn delayed bug back into proper assertion) - #164594 (rustdoc: Correctly handle inner `deprecated` attribute on modules) - #164629 (arch::breakpoint: avoid confusing 'equivalent' terminology)
…Titor document that `!` does bitwise and logical negation 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.
…uwer Rollup of 13 pull requests Successful merges: - #163664 (Add new `RUSTC_BOOTSTRAP=-allow-unstable-compiler-flags` mode for testing stable compiler behavior in UI tests) - #163104 ([debuginfo] Emit `usize` and `isize` as typedefs) - #163338 (MIR move elimination [4/6]: MoveElimination) - #163701 (add ReadDir::dir to get the directory handle of the underlying directory) - #164488 (Don't try to skip anything in `Skip::advance_by(0)`) - #164578 (Don't ignore unknown LLVM diagnostics) - #164611 (Improve bit permutation codegen) - #164612 (std: Combine `is_powerpc64_feature_detected` into `is_powerpc_feature_detected`) - #162668 (document that `!` does bitwise and logical negation) - #164264 (lint: suggest `fXX::is_nan` for unsuffixed NaN comparisons) - #164509 (layout invariant: turn delayed bug back into proper assertion) - #164594 (rustdoc: Correctly handle inner `deprecated` attribute on modules) - #164629 (arch::breakpoint: avoid confusing 'equivalent' terminology)
…uwer Rollup of 13 pull requests Successful merges: - #163664 (Add new `RUSTC_BOOTSTRAP=-allow-unstable-compiler-flags` mode for testing stable compiler behavior in UI tests) - #163104 ([debuginfo] Emit `usize` and `isize` as typedefs) - #163338 (MIR move elimination [4/6]: MoveElimination) - #163701 (add ReadDir::dir to get the directory handle of the underlying directory) - #164488 (Don't try to skip anything in `Skip::advance_by(0)`) - #164578 (Don't ignore unknown LLVM diagnostics) - #164611 (Improve bit permutation codegen) - #164612 (std: Combine `is_powerpc64_feature_detected` into `is_powerpc_feature_detected`) - #162668 (document that `!` does bitwise and logical negation) - #164264 (lint: suggest `fXX::is_nan` for unsuffixed NaN comparisons) - #164509 (layout invariant: turn delayed bug back into proper assertion) - #164594 (rustdoc: Correctly handle inner `deprecated` attribute on modules) - #164629 (arch::breakpoint: avoid confusing 'equivalent' terminology)
…Titor document that `!` does bitwise and logical negation 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.
…uwer Rollup of 15 pull requests Successful merges: - #163664 (Add new `RUSTC_BOOTSTRAP=-allow-unstable-compiler-flags` mode for testing stable compiler behavior in UI tests) - #163104 ([debuginfo] Emit `usize` and `isize` as typedefs) - #163338 (MIR move elimination [4/6]: MoveElimination) - #163701 (add ReadDir::dir to get the directory handle of the underlying directory) - #164488 (Don't try to skip anything in `Skip::advance_by(0)`) - #164611 (Improve bit permutation codegen) - #164612 (std: Combine `is_powerpc64_feature_detected` into `is_powerpc_feature_detected`) - #148842 (Avoid incorrect lifetime suggestion involving `sym::anon`) - #162668 (document that `!` does bitwise and logical negation) - #164264 (lint: suggest `fXX::is_nan` for unsuffixed NaN comparisons) - #164509 (layout invariant: turn delayed bug back into proper assertion) - #164540 (Minor optimizations around macro parsing) - #164594 (rustdoc: Correctly handle inner `deprecated` attribute on modules) - #164595 (Allow attributes in function trait parameters) - #164629 (arch::breakpoint: avoid confusing 'equivalent' terminology)
…Titor document that `!` does bitwise and logical negation 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.
…uwer Rollup of 14 pull requests Successful merges: - #163664 (Add new `RUSTC_BOOTSTRAP=-allow-unstable-compiler-flags` mode for testing stable compiler behavior in UI tests) - #163104 ([debuginfo] Emit `usize` and `isize` as typedefs) - #163701 (add ReadDir::dir to get the directory handle of the underlying directory) - #164488 (Don't try to skip anything in `Skip::advance_by(0)`) - #164611 (Improve bit permutation codegen) - #164612 (std: Combine `is_powerpc64_feature_detected` into `is_powerpc_feature_detected`) - #148842 (Avoid incorrect lifetime suggestion involving `sym::anon`) - #162668 (document that `!` does bitwise and logical negation) - #164264 (lint: suggest `fXX::is_nan` for unsuffixed NaN comparisons) - #164509 (layout invariant: turn delayed bug back into proper assertion) - #164540 (Minor optimizations around macro parsing) - #164594 (rustdoc: Correctly handle inner `deprecated` attribute on modules) - #164595 (Allow attributes in function trait parameters) - #164629 (arch::breakpoint: avoid confusing 'equivalent' terminology)
…uwer Rollup of 14 pull requests Successful merges: - #163664 (Add new `RUSTC_BOOTSTRAP=-allow-unstable-compiler-flags` mode for testing stable compiler behavior in UI tests) - #163104 ([debuginfo] Emit `usize` and `isize` as typedefs) - #163701 (add ReadDir::dir to get the directory handle of the underlying directory) - #164488 (Don't try to skip anything in `Skip::advance_by(0)`) - #164611 (Improve bit permutation codegen) - #164612 (std: Combine `is_powerpc64_feature_detected` into `is_powerpc_feature_detected`) - #148842 (Avoid incorrect lifetime suggestion involving `sym::anon`) - #162668 (document that `!` does bitwise and logical negation) - #164264 (lint: suggest `fXX::is_nan` for unsuffixed NaN comparisons) - #164509 (layout invariant: turn delayed bug back into proper assertion) - #164540 (Minor optimizations around macro parsing) - #164594 (rustdoc: Correctly handle inner `deprecated` attribute on modules) - #164595 (Allow attributes in function trait parameters) - #164629 (arch::breakpoint: avoid confusing 'equivalent' terminology)
…Titor document that `!` does bitwise and logical negation 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.
…uwer Rollup of 19 pull requests Successful merges: - #163664 (Add new `RUSTC_BOOTSTRAP=-allow-unstable-compiler-flags` mode for testing stable compiler behavior in UI tests) - #163668 (Remap syntax contexts and expansion ids for det. metadata encoding) - #160404 (fd-views: AsRef<File>&Co. for BorrowedFd) - #163104 ([debuginfo] Emit `usize` and `isize` as typedefs) - #163317 (Stop useless caching of post-LTO artifact caching for fat LTO) - #163701 (add ReadDir::dir to get the directory handle of the underlying directory) - #164488 (Don't try to skip anything in `Skip::advance_by(0)`) - #164507 (Encode HashMap and HashSet in deterministic order when an encoder requires determinism) - #164611 (Improve bit permutation codegen) - #164612 (std: Combine `is_powerpc64_feature_detected` into `is_powerpc_feature_detected`) - #148842 (Avoid incorrect lifetime suggestion involving `sym::anon`) - #162668 (document that `!` does bitwise and logical negation) - #164264 (lint: suggest `fXX::is_nan` for unsuffixed NaN comparisons) - #164509 (layout invariant: turn delayed bug back into proper assertion) - #164540 (Minor optimizations around macro parsing) - #164594 (rustdoc: Correctly handle inner `deprecated` attribute on modules) - #164595 (Allow attributes in function trait parameters) - #164641 (Stabilize `slice_split_once`) - #164646 (Adjust rustfmt subtree sync docs to not use `--allow-noop` for now)
Rollup of 20 pull requests Successful merges: - #163664 (Add new `RUSTC_BOOTSTRAP=-allow-unstable-compiler-flags` mode for testing stable compiler behavior in UI tests) - #163668 (Remap syntax contexts and expansion ids for det. metadata encoding) - #163104 ([debuginfo] Emit `usize` and `isize` as typedefs) - #163317 (Stop useless caching of post-LTO artifact caching for fat LTO) - #163701 (add ReadDir::dir to get the directory handle of the underlying directory) - #164488 (Don't try to skip anything in `Skip::advance_by(0)`) - #164507 (Encode HashMap and HashSet in deterministic order when an encoder requires determinism) - #164611 (Improve bit permutation codegen) - #164612 (std: Combine `is_powerpc64_feature_detected` into `is_powerpc_feature_detected`) - #148842 (Avoid incorrect lifetime suggestion involving `sym::anon`) - #162668 (document that `!` does bitwise and logical negation) - #164264 (lint: suggest `fXX::is_nan` for unsuffixed NaN comparisons) - #164509 (layout invariant: turn delayed bug back into proper assertion) - #164540 (Minor optimizations around macro parsing) - #164594 (rustdoc: Correctly handle inner `deprecated` attribute on modules) - #164595 (Allow attributes in function trait parameters) - #164616 (Add test for VecDeque with a custom allocator) - #164629 (arch::breakpoint: avoid confusing 'equivalent' terminology) - #164641 (Stabilize `slice_split_once`) - #164646 (Adjust rustfmt subtree sync docs to not use `--allow-noop` for now)
Rollup merge of #162668 - evan-dickinson:bitwise-not, r=JohnTitor document that `!` does bitwise and logical negation 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.
Rollup of 20 pull requests Successful merges: - rust-lang/rust#163664 (Add new `RUSTC_BOOTSTRAP=-allow-unstable-compiler-flags` mode for testing stable compiler behavior in UI tests) - rust-lang/rust#163668 (Remap syntax contexts and expansion ids for det. metadata encoding) - rust-lang/rust#163104 ([debuginfo] Emit `usize` and `isize` as typedefs) - rust-lang/rust#163317 (Stop useless caching of post-LTO artifact caching for fat LTO) - rust-lang/rust#163701 (add ReadDir::dir to get the directory handle of the underlying directory) - rust-lang/rust#164488 (Don't try to skip anything in `Skip::advance_by(0)`) - rust-lang/rust#164507 (Encode HashMap and HashSet in deterministic order when an encoder requires determinism) - rust-lang/rust#164611 (Improve bit permutation codegen) - rust-lang/rust#164612 (std: Combine `is_powerpc64_feature_detected` into `is_powerpc_feature_detected`) - rust-lang/rust#148842 (Avoid incorrect lifetime suggestion involving `sym::anon`) - rust-lang/rust#162668 (document that `!` does bitwise and logical negation) - rust-lang/rust#164264 (lint: suggest `fXX::is_nan` for unsuffixed NaN comparisons) - rust-lang/rust#164509 (layout invariant: turn delayed bug back into proper assertion) - rust-lang/rust#164540 (Minor optimizations around macro parsing) - rust-lang/rust#164594 (rustdoc: Correctly handle inner `deprecated` attribute on modules) - rust-lang/rust#164595 (Allow attributes in function trait parameters) - rust-lang/rust#164616 (Add test for VecDeque with a custom allocator) - rust-lang/rust#164629 (arch::breakpoint: avoid confusing 'equivalent' terminology) - rust-lang/rust#164641 (Stabilize `slice_split_once`) - rust-lang/rust#164646 (Adjust rustfmt subtree sync docs to not use `--allow-noop` for now)
Rollup of 20 pull requests Successful merges: - rust-lang/rust#163664 (Add new `RUSTC_BOOTSTRAP=-allow-unstable-compiler-flags` mode for testing stable compiler behavior in UI tests) - rust-lang/rust#163668 (Remap syntax contexts and expansion ids for det. metadata encoding) - rust-lang/rust#163104 ([debuginfo] Emit `usize` and `isize` as typedefs) - rust-lang/rust#163317 (Stop useless caching of post-LTO artifact caching for fat LTO) - rust-lang/rust#163701 (add ReadDir::dir to get the directory handle of the underlying directory) - rust-lang/rust#164488 (Don't try to skip anything in `Skip::advance_by(0)`) - rust-lang/rust#164507 (Encode HashMap and HashSet in deterministic order when an encoder requires determinism) - rust-lang/rust#164611 (Improve bit permutation codegen) - rust-lang/rust#164612 (std: Combine `is_powerpc64_feature_detected` into `is_powerpc_feature_detected`) - rust-lang/rust#148842 (Avoid incorrect lifetime suggestion involving `sym::anon`) - rust-lang/rust#162668 (document that `!` does bitwise and logical negation) - rust-lang/rust#164264 (lint: suggest `fXX::is_nan` for unsuffixed NaN comparisons) - rust-lang/rust#164509 (layout invariant: turn delayed bug back into proper assertion) - rust-lang/rust#164540 (Minor optimizations around macro parsing) - rust-lang/rust#164594 (rustdoc: Correctly handle inner `deprecated` attribute on modules) - rust-lang/rust#164595 (Allow attributes in function trait parameters) - rust-lang/rust#164616 (Add test for VecDeque with a custom allocator) - rust-lang/rust#164629 (arch::breakpoint: avoid confusing 'equivalent' terminology) - rust-lang/rust#164641 (Stabilize `slice_split_once`) - rust-lang/rust#164646 (Adjust rustfmt subtree sync docs to not use `--allow-noop` for now)
The documentation summary for
core::ops::Notsays that it performslogical 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.