Checked/wrapping/strict/unbounded funnel shifts #161119
r? @JohnTitor
rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.
Use r? to explicitly pick a reviewer
<details>
<summary>Why was this reviewer chosen?</summary>
The reviewer was selected based on:
libslibs expanded to 12 candidatesJohnTitor, Mark-Simulacrum, clarfonthey, nia-e, tgross35</details>
Please create a new tracking issue. I think it's fine to do even before the ACP is accepted
We will update this PR when we are next back at our computer on Monday for other reasons anyway (adding strict versions, adding tests), so we will make a tracking issue and list it then too.
:umbrella: The latest upstream changes (presumably #161719) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.
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.
All of the summary lines say "Performs a left/right funnel shift." Please update these to be a bit more similar to the {checked,wrapping,strict,unbounded}_{shl,shr}.
Please add examples
Use "would" rather than "might" because we guarantee it would do one of those two things.
Include the "Beware that, unlike most other wrapping_* methods on integer" from wrapping_shl, adapted to funnel shifts. The result can be extra unintuitive because of the reason mentioned at https://github.com/rust-lang/libs-team/issues/642#issuecomment-3231967424, try to capture that in an example.
(same for wrapping_funnel_shr)
The strict_* methods have a subsection "overflow behavior". I don't love that, but this should be consistent
https://doc.rust-lang.org/nightly/std/primitive.u32.html#method.strict_shl
These should probably go in the overflow_panic module like the other strict_* functions to be consistent. Though I'm not really sure why that module exists.
These aren't actually testing anything other than the fact that we don't panic?
These methods should be tested in test_funnel_shifts_runtime and test_funnel_shift
Reminder, once the PR becomes ready for a review, use @rustbot ready.
Apologies for the unannounced delay; we should get back to working on this in the next few days.
:umbrella: The latest upstream changes (presumably #163465) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.
@pthariensflame gentle ping :)
@pthariensflame gentle ping :)
@tgross35 Ping acknowledged gratefully; working our way back to this stuff now, hoping to get things done tomorrow even. ❤️
No pressure! Just something that's close to done and would be nice to have.
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.
No pressure! Just something that's close to done and would be nice to have.
Finally got around to doing the big rebase! None of your comments have been addressed yet, but we're now on the path to doing so shortly.
The job test-x86_64-gnu-miri failed! Check out the build log: (web) (plain enhanced) (plain)
<details><summary><i>Click to see the possible cause of the failure (guessed by this bot)</i></summary>
| ^^^^^^^^^^^^^
|
= note: `#[warn(stable_features)]` on by default
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(wrapping_funnel_shifts)]`
--> library/core/src/num/uint_macros.rs:568:13
|
1 | / macro_rules! uint_impl {
2 | | (
3 | | Self = $SelfT:ty,
4 | | ActualT = $ActualT:ident,
... |
568 | | self.wrapping_funnel_shl(right, n)
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
... |
4518 | | }
---
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
563 + #[rustc_const_unstable(feature = "...", issue = "...")]
564 | pub const fn funnel_shl(self, right: Self, n: u32) -> Self {
|
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(wrapping_funnel_shifts)]`
--> library/core/src/num/uint_macros.rs:632:13
|
1 | / macro_rules! uint_impl {
2 | | (
3 | | Self = $SelfT:ty,
4 | | ActualT = $ActualT:ident,
... |
632 | | self.wrapping_funnel_shr(right, n)
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
... |
4518 | | }
---
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
627 + #[rustc_const_unstable(feature = "...", issue = "...")]
628 | pub const fn funnel_shr(self, right: Self, n: u32) -> Self {
|
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(wrapping_funnel_shifts)]`
--> library/core/src/num/uint_macros.rs:568:13
|
1 | / macro_rules! uint_impl {
2 | | (
3 | | Self = $SelfT:ty,
4 | | ActualT = $ActualT:ident,
... |
568 | | self.wrapping_funnel_shl(right, n)
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
... |
4518 | | }
---
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
563 + #[rustc_const_unstable(feature = "...", issue = "...")]
564 | pub const fn funnel_shl(self, right: Self, n: u32) -> Self {
|
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(wrapping_funnel_shifts)]`
--> library/core/src/num/uint_macros.rs:632:13
|
1 | / macro_rules! uint_impl {
2 | | (
3 | | Self = $SelfT:ty,
4 | | ActualT = $ActualT:ident,
... |
632 | | self.wrapping_funnel_shr(right, n)
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
... |
4518 | | }
---
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
627 + #[rustc_const_unstable(feature = "...", issue = "...")]
628 | pub const fn funnel_shr(self, right: Self, n: u32) -> Self {
|
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(wrapping_funnel_shifts)]`
--> library/core/src/num/uint_macros.rs:568:13
|
1 | / macro_rules! uint_impl {
2 | | (
3 | | Self = $SelfT:ty,
4 | | ActualT = $ActualT:ident,
... |
568 | | self.wrapping_funnel_shl(right, n)
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
... |
4518 | | }
---
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
563 + #[rustc_const_unstable(feature = "...", issue = "...")]
564 | pub const fn funnel_shl(self, right: Self, n: u32) -> Self {
|
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(wrapping_funnel_shifts)]`
--> library/core/src/num/uint_macros.rs:632:13
|
1 | / macro_rules! uint_impl {
2 | | (
3 | | Self = $SelfT:ty,
4 | | ActualT = $ActualT:ident,
... |
632 | | self.wrapping_funnel_shr(right, n)
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
... |
4518 | | }
---
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
627 + #[rustc_const_unstable(feature = "...", issue = "...")]
628 | pub const fn funnel_shr(self, right: Self, n: u32) -> Self {
|
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(wrapping_funnel_shifts)]`
--> library/core/src/num/uint_macros.rs:568:13
|
1 | / macro_rules! uint_impl {
2 | | (
3 | | Self = $SelfT:ty,
4 | | ActualT = $ActualT:ident,
... |
568 | | self.wrapping_funnel_shl(right, n)
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
... |
4518 | | }
---
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
563 + #[rustc_const_unstable(feature = "...", issue = "...")]
564 | pub const fn funnel_shl(self, right: Self, n: u32) -> Self {
|
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(wrapping_funnel_shifts)]`
--> library/core/src/num/uint_macros.rs:632:13
|
1 | / macro_rules! uint_impl {
2 | | (
3 | | Self = $SelfT:ty,
4 | | ActualT = $ActualT:ident,
... |
632 | | self.wrapping_funnel_shr(right, n)
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
... |
4518 | | }
---
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
627 + #[rustc_const_unstable(feature = "...", issue = "...")]
628 | pub const fn funnel_shr(self, right: Self, n: u32) -> Self {
|
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(wrapping_funnel_shifts)]`
--> library/core/src/num/uint_macros.rs:568:13
|
1 | / macro_rules! uint_impl {
2 | | (
3 | | Self = $SelfT:ty,
4 | | ActualT = $ActualT:ident,
... |
568 | | self.wrapping_funnel_shl(right, n)
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
... |
4518 | | }
---
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
563 + #[rustc_const_unstable(feature = "...", issue = "...")]
564 | pub const fn funnel_shl(self, right: Self, n: u32) -> Self {
|
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(wrapping_funnel_shifts)]`
--> library/core/src/num/uint_macros.rs:632:13
|
1 | / macro_rules! uint_impl {
2 | | (
3 | | Self = $SelfT:ty,
4 | | ActualT = $ActualT:ident,
... |
632 | | self.wrapping_funnel_shr(right, n)
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
... |
4518 | | }
---
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
627 + #[rustc_const_unstable(feature = "...", issue = "...")]
628 | pub const fn funnel_shr(self, right: Self, n: u32) -> Self {
|
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(wrapping_funnel_shifts)]`
--> library/core/src/num/uint_macros.rs:568:13
|
1 | / macro_rules! uint_impl {
2 | | (
3 | | Self = $SelfT:ty,
4 | | ActualT = $ActualT:ident,
... |
568 | | self.wrapping_funnel_shl(right, n)
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
... |
4518 | | }
---
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
563 + #[rustc_const_unstable(feature = "...", issue = "...")]
564 | pub const fn funnel_shl(self, right: Self, n: u32) -> Self {
|
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(wrapping_funnel_shifts)]`
--> library/core/src/num/uint_macros.rs:632:13
|
1 | / macro_rules! uint_impl {
2 | | (
3 | | Self = $SelfT:ty,
4 | | ActualT = $ActualT:ident,
... |
632 | | self.wrapping_funnel_shr(right, n)
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
... |
4518 | | }
---
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
627 + #[rustc_const_unstable(feature = "...", issue = "...")]
628 | pub const fn funnel_shr(self, right: Self, n: u32) -> Self {
|
[RUSTC-TIMING] core test:false 12.824
error: `core` (lib) generated 1 warning
error: could not compile `core` (lib) due to 12 previous errors; 1 warning emitted
</details>
:umbrella: The latest upstream changes (presumably #166567) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.
tgross35
pthariensflame
<!-- homu-ignore:start -->
<!--
Please read our [LLM policy] before opening a PR,
If you used an LLM to generate any part of this PR, including the PR description, please disclose that according to our [guidelines][disclosure guidelines].
LLM contributions are not banned, but are held to a higher standard of review and correctness.
[LLM policy]: https://forge.rust-lang.org/policies/llm-usage.html
[disclosure guidelines]: https://rustc-dev-guide.rust-lang.org/llm-guidance/writing.html#disclosure-guidelines
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.
This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using
r? <reviewer name>
When merged, your PR's description becomes part of the commit message of a merge commit.
If you do not want certain parts of it (such as your LLM disclosure) to show up in the permanent git history,
surround them with a pair of HTML comments containing
homu-ignore:startandhomu-ignore:end.-->
<!-- homu-ignore:end -->
This implements the wrapping funnel shifts requested at https://github.com/rust-lang/libs-team/issues/642#issuecomment-3231967424 and also some additional forms of funnel shift proposed at https://github.com/rust-lang/libs-team/issues/855; this might interact with rust-lang/rust#161015, which is attempting to stabilize the original funnel shift methods.
The work in this PR was done entirely by some people inside a human brain, without the use of any LLMs…or much use of an IDE since ours kept crashing during this process and we had to resort to a plain text editor. 😅
This implements the tracking issue rust-lang/rust#161798.