Uh oh!
There was an error while loading. Please reload this page.
Add extra unchecked_disjoint_bitor implementations. - #147368
Conversation
rustbot
commented
Oct 5, 2025
rustbot has assigned @Mark-Simulacrum. Use |
bjoernager
commented
Oct 5, 2025
@rustbot label +T-libs-api -T-libs r? libs-api |
This comment has been minimized.
This comment has been minimized.
943d050 to
845a872Compare
This comment was marked as outdated.
This comment was marked as outdated.
bjoernager
commented
Jan 5, 2026
r? libs-api |
This comment has been minimized.
This comment has been minimized.
rustbot
commented
May 20, 2026
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Seems reasonable to me but should get a @rust-lang/libs-api okay.
@rustbot label +I-libs-api-nominated
r? tgross35
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| } | ||
| /// Same value as `self | other`, but UB if any bit position is set in both inputs. | ||
| /// Disjoint, bitwise or. Computes `self | rhs`, assuming no one bits in common. |
There was a problem hiding this comment.
"assuming no one bits in common" -> "assuming there are no one bits in common."
Or something like "Computes self | rhs given the precondition that no set bits of the inputs overlap."
| /// `((a as u32) << 16) | (b as u32)`, that's fine, as the backend will | ||
| /// know those sides of the `|` are disjoint without needing help. | ||
| /// Practically, this requires that `self | rhs`, `self ^ rhs`, and `self + rhs` all | ||
| /// yield the same result, allowing for any of the three to be emitted in code gen |
There was a problem hiding this comment.
Nit: "code gen" -> either "codegen" or "code generation"
There was a problem hiding this comment.
What is wrong with "code gen" ? It's already used in the repo: https://github.com/search?q=repo%3Arust-lang%2Frust%20%22code%20gen%22&type=code.
There was a problem hiding this comment.
Most of those hits are part of "code generation" https://github.com/search?q=repo%3Arust-lang%2Frust+%2Fcode+gen%5Cb%2F&type=code. Loosely I think "gen" is considered an abbreviation rather than a word that can stand on its own, but we do consider "codegen" to be one.
Also we have codegen-units, codegen-backend etc. rather than code-gen-units and code-gen-backend.
…'i64', 'i128', and 'isize'; Update existing 'unchecked_disjoint_bitor' docs; Add 'must_use' to 'unchecked_disjoint_bitor';
| if self { Ok(()) } else { Err(f()) } | ||
| } | ||
| /// Disjoint, bitwise or. Computes `self | rhs`, assuming inequality. |
There was a problem hiding this comment.
| /// Disjoint, bitwise or. Computes `self | rhs`, assuming inequality. | |
| /// Disjoint, bitwise or. Computes `self | rhs`, assuming at most one is `true`. |
Right, or no? I'd expect (false, false) to be valid.
| /// #![feature(disjoint_bitor)] | ||
| /// | ||
| /// assert_eq!( | ||
| /// // SAFETY: `false` and `true` are inequal. |
There was a problem hiding this comment.
| /// // SAFETY: `false` and `true` are inequal. | |
| /// // SAFETY: `false` and `true` have no bits in common. |
As above.
There was a problem hiding this comment.
I actually requested this move away from talking about bits with booleans, since I don't think users should need to think about the representation when thinking about values is sufficient. But looks like I gave a bad suggestion here.
So perhaps "has only one true" or "has at most one true"?
There was a problem hiding this comment.
Adding a false, false test to the doc would be good too
There was a problem hiding this comment.
| /// // SAFETY: `false` and `true` are inequal. | |
| /// // SAFETY: `false` and `true` are not both `true`. |
| /// | ||
| /// # Safety | ||
| /// | ||
| /// This results in undefined behaviour if `self` and `rhs` are equal. |
There was a problem hiding this comment.
| /// This results in undefined behaviour if `self` and `rhs` are equal. | |
| /// This results in undefined behavior if `self` and `rhs` are both `true`. |
As above.
Nit: We generally use American spellings.
| pub const unsafe fn unchecked_disjoint_bitor(self, rhs: Self) -> Self { | ||
| assert_unsafe_precondition!( | ||
| check_language_ub, | ||
| "bool::unchecked_disjoint_bitor cannot bitor equal values", |
There was a problem hiding this comment.
| "bool::unchecked_disjoint_bitor cannot bitor equal values", | |
| "bool::unchecked_disjoint_bitor cannot bitor overlapping ones", |
As above.
There was a problem hiding this comment.
Similarly, maybe "more than one true"
There was a problem hiding this comment.
| "bool::unchecked_disjoint_bitor cannot bitor equal values", | |
| "bool::unchecked_disjoint_bitor cannot bitor two `true` values", |
| ( | ||
| lhs: bool = self, | ||
| rhs: bool = rhs, | ||
| ) => lhs != rhs, |
There was a problem hiding this comment.
| ) => lhs != rhs, | |
| ) => !(lhs && rhs), |
Right? As above, I'd expect (false, false) to be valid.
nia-e
commented
Jun 2, 2026
We discussed this in today's libs-api meeting; we're happy to add these functions. Thanks! |
tgross35
commented
Jun 8, 2026
Just a couple of small remaining review comments @rustbot author |
rustbot
commented
Jun 8, 2026
Reminder, once the PR becomes ready for a review, use |
☔ The latest upstream changes (presumably #159336) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
View all comments
Tracking issue: #135758.
This PR implements the
unchecked_disjoint_bitormethod for additional types:Our
disjoint_bitorintrinsic is already implemented for these types. This method specifically is also already present on unsigned, integral types.Additionally, this PR rewrites the existing docs for
unchecked_disjoint_bitorand adds themust_useattribute to the method.