document behavior of rotations for n >= BITS

This commit is contained in:
Ralf Jung 2025-11-04 15:33:11 +01:00
parent bc809befe2
commit 434cb5e700
2 changed files with 20 additions and 0 deletions

View file

@ -275,6 +275,10 @@ macro_rules! int_impl {
/// Shifts the bits to the left by a specified amount, `n`,
/// wrapping the truncated bits to the end of the resulting integer.
///
/// `rotate_left(n)` is equivalent to applying `rotate_left(1)` a total of `n` times. In
/// particular, a rotation by the number of bits in `self` returns the input value
/// unchanged.
///
/// Please note this isn't the same operation as the `<<` shifting operator!
///
/// # Examples
@ -284,6 +288,7 @@ macro_rules! int_impl {
#[doc = concat!("let m = ", $rot_result, ";")]
///
#[doc = concat!("assert_eq!(n.rotate_left(", $rot, "), m);")]
#[doc = concat!("assert_eq!(n.rotate_left(1024), n);")]
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
@ -298,6 +303,10 @@ macro_rules! int_impl {
/// wrapping the truncated bits to the beginning of the resulting
/// integer.
///
/// `rotate_right(n)` is equivalent to applying `rotate_right(1)` a total of `n` times. In
/// particular, a rotation by the number of bits in `self` returns the input value
/// unchanged.
///
/// Please note this isn't the same operation as the `>>` shifting operator!
///
/// # Examples
@ -307,6 +316,7 @@ macro_rules! int_impl {
#[doc = concat!("let m = ", $rot_op, ";")]
///
#[doc = concat!("assert_eq!(n.rotate_right(", $rot, "), m);")]
#[doc = concat!("assert_eq!(n.rotate_right(1024), n);")]
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]