@@ -188,8 +188,6 @@ impl<T: fmt::UpperHex> fmt::UpperHex for Wrapping<T> {
188188 }
189189}
190190
191- mod wrapping;
192-
193191// All these modules are technically private and only exposed for coretests:
194192pub mod flt2dec;
195193pub mod dec2flt;
@@ -203,6 +201,8 @@ macro_rules! doc_comment {
203201 } ;
204202}
205203
204+ mod wrapping;
205+
206206// `Int` + `SignedInt` implemented for signed integers
207207macro_rules! int_impl {
208208 ( $SelfT: ty, $ActualT: ident, $UnsignedT: ty, $BITS: expr, $Min: expr, $Max: expr, $Feature: expr,
@@ -3423,6 +3423,29 @@ $EndFeature, "
34233423 }
34243424 }
34253425
3426+ doc_comment! {
3427+ concat!( "Returns the smallest power of two greater than or equal to `n`. If
3428+ the next power of two is greater than the type's maximum value,
3429+ the return value is wrapped to `0`.
3430+
3431+ # Examples
3432+
3433+ Basic usage:
3434+
3435+ ```
3436+ #![feature(wrapping_int_impl)]
3437+ " , $Feature, "
3438+ assert_eq!(2" , stringify!( $SelfT) , ".wrapping_next_power_of_two(), 2);
3439+ assert_eq!(3" , stringify!( $SelfT) , ".wrapping_next_power_of_two(), 4);
3440+ assert_eq!(" , stringify!( $SelfT) , "::max_value().wrapping_next_power_of_two(), 0);" ,
3441+ $EndFeature, "
3442+ ```" ) ,
3443+ #[ unstable( feature = "wrapping_int_impl" , issue = "32463" ) ]
3444+ pub fn wrapping_next_power_of_two( self ) -> Self {
3445+ self . one_less_than_next_power_of_two( ) . wrapping_add( 1 )
3446+ }
3447+ }
3448+
34263449 /// Return the memory representation of this integer as a byte array.
34273450 ///
34283451 /// The target platform’s native endianness is used.
0 commit comments