Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking Issue for NonZero*::count_ones #120287

Open
1 of 3 tasks
WaffleLapkin opened this issue Jan 24, 2024 · 8 comments
Open
1 of 3 tasks

Tracking Issue for NonZero*::count_ones #120287

WaffleLapkin opened this issue Jan 24, 2024 · 8 comments
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@WaffleLapkin
Copy link
Member

Feature gate: #![feature(non_zero_count_ones)]

This is a tracking issue for NonZero*::count_ones family of methods.

Public API

// core::num

impl NonZero* {
    pub fn count_ones(self) -> NonZeroU32;
}

Steps / History

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@WaffleLapkin WaffleLapkin added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC labels Jan 24, 2024
@tyilo
Copy link
Contributor

tyilo commented Nov 8, 2024

Anything holding this back from getting stabilized?

@WaffleLapkin
Copy link
Member Author

@tyilo nothing that I'm aware of.

@rust-lang/libs-api I would like to propose this feature for stabilization. This feature adds a very straightforward function:

impl NonZero* {
    pub fn count_ones(self) -> NonZeroU32;
}

The benefit here, as opposed to writing .get().count_ones(), is that NonZero::count_ones returns NonZeroU32 and not u32 (a non-zero number must have at least one bit set!). The implementation is very simple and hasn't changed since the original addition in 1.77.

@tyilo
Copy link
Contributor

tyilo commented Nov 9, 2024

I understand that this returns NonZeroU32 because <integer>::count_ones returns u32.

But why u32 and not u8 or u16?

u8 would work for all current primitive integers, but not for the potential u256 and i256.
u16 would first fail when introducing u65536 and i65536 which seems unlikely to ever happen.

@WaffleLapkin
Copy link
Member Author

@tyilo it's not necessarily that we have to use 32 bits, and more so that u32 is the default integer type for when you don't really care about the width. you may notice that it's not only count_ones, but a lot of things like BITS, ilog, {leading,trailing}_{zeros,ones}, etc.

@WaffleLapkin WaffleLapkin added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Nov 19, 2024
@Amanieu
Copy link
Member

Amanieu commented Nov 25, 2024

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Nov 25, 2024

Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Nov 25, 2024
@Amanieu Amanieu removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. labels Nov 25, 2024
@rfcbot rfcbot added the disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. label Nov 25, 2024
@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Jan 27, 2025
@rfcbot
Copy link

rfcbot commented Jan 27, 2025

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Feb 6, 2025
@rfcbot
Copy link

rfcbot commented Feb 6, 2025

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@rfcbot rfcbot added the to-announce Announce this issue on triage meeting label Feb 6, 2025
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Feb 7, 2025
jhpratt added a commit to jhpratt/rust that referenced this issue Feb 11, 2025
jhpratt added a commit to jhpratt/rust that referenced this issue Feb 11, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 11, 2025
Rollup merge of rust-lang#136663 - WaffleLapkin:count-non-zero-ones, r=cuviper

Stabilize `NonZero::count_ones`

As per rust-lang#120287 (comment)

r? libs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants