]> git.lizzy.rs Git - rust.git/commitdiff
Add `popcount` and `popcnt` as doc aliases for `count_ones` methods.
authorSimon Sapin <simon.sapin@exyr.org>
Wed, 16 Dec 2020 22:51:18 +0000 (23:51 +0100)
committerSimon Sapin <simon.sapin@exyr.org>
Wed, 16 Dec 2020 23:22:48 +0000 (00:22 +0100)
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

library/core/src/num/int_macros.rs
library/core/src/num/uint_macros.rs
library/core/src/num/wrapping.rs

index 4fa48427ec6e6d548cd010af79832fc4788c06a9..2cde5d9995b62ec9908e8212ce880f595e08e302 100644 (file)
@@ -92,6 +92,8 @@ pub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError> {
 "),
             #[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() }
         }
index 390c1b7e9e8710f3ea415f61e7509fce07b29c7b..ae8fc18a83882adec91e0e542b95653975abb7e1 100644 (file)
@@ -90,6 +90,8 @@ pub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError> {
 ```"),
             #[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
index 5324dfdeddde281ce17470651429f5f01f47f644..77c9a93008c91c3e28354639532b111c1ba09e6e 100644 (file)
@@ -453,6 +453,8 @@ impl Wrapping<$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()