summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2020-12-16 23:51:18 +0100
committerSimon Sapin <simon.sapin@exyr.org>2020-12-17 00:22:48 +0100
commitf365de353ad3d48b5e9269ebc373f82d5aeb19d0 (patch)
tree553cc71e9a3a448a9ae75bfa4ff8c2b7b7a00371
parentb32e6e6ac8921035177256ab6806e6ab0d4b9b94 (diff)
downloadrust-f365de353ad3d48b5e9269ebc373f82d5aeb19d0.tar.gz
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
-rw-r--r--library/core/src/num/int_macros.rs2
-rw-r--r--library/core/src/num/uint_macros.rs2
-rw-r--r--library/core/src/num/wrapping.rs2
3 files changed, 6 insertions, 0 deletions
diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs
index 4fa48427ec6..2cde5d9995b 100644
--- a/library/core/src/num/int_macros.rs
+++ b/library/core/src/num/int_macros.rs
@@ -92,6 +92,8 @@ $EndFeature, "
"),
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
+ #[doc(alias = "popcount")]
+ #[doc(alias = "popcnt")]
#[inline]
pub const fn count_ones(self) -> u32 { (self as $UnsignedT).count_ones() }
}
diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs
index 390c1b7e9e8..ae8fc18a838 100644
--- a/library/core/src/num/uint_macros.rs
+++ b/library/core/src/num/uint_macros.rs
@@ -90,6 +90,8 @@ assert_eq!(n.count_ones(), 3);", $EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_math", since = "1.32.0")]
+ #[doc(alias = "popcount")]
+ #[doc(alias = "popcnt")]
#[inline]
pub const fn count_ones(self) -> u32 {
intrinsics::ctpop(self as $ActualT) as u32
diff --git a/library/core/src/num/wrapping.rs b/library/core/src/num/wrapping.rs
index 5324dfdeddd..77c9a93008c 100644
--- a/library/core/src/num/wrapping.rs
+++ b/library/core/src/num/wrapping.rs
@@ -453,6 +453,8 @@ let n = Wrapping(0b01001100", stringify!($t), ");
assert_eq!(n.count_ones(), 3);
```"),
#[inline]
+ #[doc(alias = "popcount")]
+ #[doc(alias = "popcnt")]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn count_ones(self) -> u32 {
self.0.count_ones()