Skip to content

Commit e4735dd

Browse files
authored
Rollup merge of #80097 - SimonSapin:popcount, r=m-ou-se
Add `popcount` and `popcnt` as doc aliases for `count_ones` methods. Integer types have a `count_ones` method that end up calling `intrinsics::ctpop`. On some architectures, that intrinsic is translated as a corresponding CPU instruction know as "popcount" or "popcnt". This PR makes it so that searching for those names in rustdoc shows those methods. CC https://blog.rust-lang.org/2020/11/19/Rust-1.48.html#adding-search-aliases
2 parents 5ce62da + f365de3 commit e4735dd

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

library/core/src/num/int_macros.rs

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ $EndFeature, "
9292
"),
9393
#[stable(feature = "rust1", since = "1.0.0")]
9494
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
95+
#[doc(alias = "popcount")]
96+
#[doc(alias = "popcnt")]
9597
#[inline]
9698
pub const fn count_ones(self) -> u32 { (self as $UnsignedT).count_ones() }
9799
}

library/core/src/num/uint_macros.rs

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ assert_eq!(n.count_ones(), 3);", $EndFeature, "
9090
```"),
9191
#[stable(feature = "rust1", since = "1.0.0")]
9292
#[rustc_const_stable(feature = "const_math", since = "1.32.0")]
93+
#[doc(alias = "popcount")]
94+
#[doc(alias = "popcnt")]
9395
#[inline]
9496
pub const fn count_ones(self) -> u32 {
9597
intrinsics::ctpop(self as $ActualT) as u32

library/core/src/num/wrapping.rs

+2
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ let n = Wrapping(0b01001100", stringify!($t), ");
453453
assert_eq!(n.count_ones(), 3);
454454
```"),
455455
#[inline]
456+
#[doc(alias = "popcount")]
457+
#[doc(alias = "popcnt")]
456458
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
457459
pub const fn count_ones(self) -> u32 {
458460
self.0.count_ones()

0 commit comments

Comments
 (0)