-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
implement .trailing_ones(), .leading_ones() #55715
implement .trailing_ones(), .leading_ones() #55715
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @KodrAus (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
assert_eq!(n.leading_ones(), 0);", | ||
$EndFeature, " | ||
```"), | ||
#[unstable(feature = "leading_ones_trailing_ones", issue = "0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not on the libs team but it might be a good idea to open an issue so you have a non-zero number you can refer to here :)
Signed-off-by: Yoshua Wuyts <[email protected]>
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
``` | ||
", $Feature, "let n = 0b10110011", stringify!($SelfT), "; | ||
|
||
assert_eq!(n.leading_ones(), 1);", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this will pass -- this will have no leading ones for any type size but u8
.
Basic usage: | ||
|
||
``` | ||
", $Feature, "let n = 0b10110011", stringify!($SelfT), "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tidy is saying that you need #![feature(leading_ones_trailing_ones)]
in the doctests.
Triage; @yoshuawuyts Hello, have you been able to get back this PR? |
@Aaronepower Thanks for reaching out! Ooph, no -- I've been super busy, and about to go on holiday. If it's not too much trouble, I'd love to keep this open for a few more weeks so I can hack on it once I'm back. |
ping from triage @yoshuawuyts any updates on this? |
@Dylan-DPC not yet; haven't forgotten about it! -- I'm planning to tackle this next week! 🎉 |
Ping from triage @yoshuawuyts: What is the status of this PR? |
$EndFeature, " | ||
```"), | ||
#[unstable(feature = "leading_ones_trailing_ones", issue = "0")] | ||
#[rustc_const_unstable(feature = "const_int_ops")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just remove this; I think it's fairly certain that we'll want it to be const fn
when stabilizing.
$EndFeature, " | ||
```"), | ||
#[unstable(feature = "leading_ones_trailing_ones", issue = "0")] | ||
#[rustc_const_unstable(feature = "const_int_ops")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, I'd remove this line.
assert_eq!(n.leading_ones(), 2);", $EndFeature, " | ||
```"), | ||
#[unstable(feature = "leading_ones_trailing_ones", issue = "0")] | ||
#[rustc_const_unstable(feature = "const_int_ops")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here...
assert_eq!(n.trailing_ones(), 2);", $EndFeature, " | ||
```"), | ||
#[unstable(feature = "leading_ones_trailing_ones", issue = "0")] | ||
#[rustc_const_unstable(feature = "const_int_ops")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here.
Update: I've spent some time building this out again yesterday, but ran into build problems with Rust itself. Sorry this is taking a while! |
Created an issue for this PR in #57969. If someone else would like to carry this PR over the finish line that'd be grand! -- I feel we're really close; it just requires passing lints + feature labels. |
ping from triage @yoshuawuyts closing this due to inactivity and since you are not planning of taking this forward. Thanks! |
Hi!
This patch implements
.trailing_ones()
and.leading_ones()
to all number types as counterparts to the.leading_zeros()
, and.trailing_zeros()
methods.I posted a pre-RFC for these changes on internals, but the consensus seemed to be these changes would be small enough that no RFC was needed. So hence this patch!
I've never written a PR for Rustc before, so I hope I'm doing everything right. I realize this patch is probably not good enough to land as-is, so I had a few questions:
tidy
checks are pointing out it's malformed, but I'm not sure what the correct form would be.Thanks heaps!