Rollup merge of #125884 - Rua:integer_sign_cast, r=Mark-Simulacrum · model-checking/verify-rust-std@7881d33 (original) (raw)
`@@ -183,6 +183,30 @@ macro_rules! int_impl {
`
183
183
`(self as $UnsignedT).trailing_ones()
`
184
184
`}
`
185
185
``
``
186
`` +
/// Returns the bit pattern of self
reinterpreted as an unsigned integer of the same size.
``
``
187
`+
///
`
``
188
`` +
/// This produces the same result as an as
cast, but ensures that the bit-width remains
``
``
189
`+
/// the same.
`
``
190
`+
///
`
``
191
`+
/// # Examples
`
``
192
`+
///
`
``
193
`+
/// Basic usage:
`
``
194
`+
///
`
``
195
/// ```
``
196
`+
/// #![feature(integer_sign_cast)]
`
``
197
`+
///
`
``
198
`+
#[doc = concat!("let n = -1", stringify!($SelfT), ";")]
`
``
199
`+
///
`
``
200
`+
#[doc = concat!("assert_eq!(n.cast_unsigned(), ", stringify!($UnsignedT), "::MAX);")]
`
``
201
/// ```
``
202
`+
#[unstable(feature = "integer_sign_cast", issue = "125882")]
`
``
203
`+
#[must_use = "this returns the result of the operation, \
`
``
204
`+
without modifying the original"]
`
``
205
`+
#[inline(always)]
`
``
206
`+
pub const fn cast_unsigned(self) -> $UnsignedT {
`
``
207
`+
self as $UnsignedT
`
``
208
`+
}
`
``
209
+
186
210
`` /// Shifts the bits to the left by a specified amount, n
,
``
187
211
`/// wrapping the truncated bits to the end of the resulting integer.
`
188
212
`///
`