Rollup merge of #155559 - safer-rust:fix-doc2, r=jhpratt

add safety doc (section header) to two unsafe methods in `NonZero`

This PR adds a Safety section to two unsafe methods in `NonZero`:
- [unchecked_add](https://doc.rust-lang.org/nightly/core/num/struct.NonZero.html#method.unchecked_add)
- [unchecked_mul](https://doc.rust-lang.org/nightly/core/num/struct.NonZero.html#method.unchecked_mul)

The safety documentation is now consistent with that of [`u8::unchecked_add`](https://doc.rust-lang.org/nightly/core/primitive.u8.html#method.unchecked_add) and [`u8::unchecked_mul`](https://doc.rust-lang.org/nightly/core/primitive.u8.html#method.unchecked_mul).
This commit is contained in:
Jacob Pratt
2026-04-21 02:20:26 -04:00
committed by GitHub
+8 -2
View File
@@ -1118,7 +1118,10 @@ pub const fn saturating_mul(self, other: Self) -> Self {
/// assuming overflow cannot occur.
/// Overflow is unchecked, and it is undefined behavior to overflow
/// *even if the result would wrap to a non-zero value*.
/// The behavior is undefined as soon as
///
/// # Safety
///
/// This results in undefined behavior when
#[doc = sign_dependent_expr!{
$signedness ?
if signed {
@@ -1695,7 +1698,10 @@ pub const fn saturating_add(self, other: $Int) -> Self {
/// assuming overflow cannot occur.
/// Overflow is unchecked, and it is undefined behavior to overflow
/// *even if the result would wrap to a non-zero value*.
/// The behavior is undefined as soon as
///
/// # Safety
///
/// This results in undefined behavior when
#[doc = concat!("`self + rhs > ", stringify!($Int), "::MAX`.")]
///
/// # Examples