@@ -351,6 +351,34 @@ macro_rules! nonzero_unsigned_operations {
351
351
// so the result cannot be zero.
352
352
unsafe { $Ty:: new_unchecked( self . get( ) . saturating_add( other) ) }
353
353
}
354
+
355
+ /// Add an unsigned integer to a non-zero value,
356
+ /// assuming overflow cannot occur.
357
+ /// This results in undefined behaviour when
358
+ #[ doc = concat!( "`self + rhs > " , stringify!( $Int) , "::MAX`" ) ]
359
+ #[ doc = concat!( " or `self + rhs < " , stringify!( $Int) , "::MIN`." ) ]
360
+ ///
361
+ /// # Examples
362
+ ///
363
+ /// ```
364
+ /// #![feature(nonzero_ops)]
365
+ /// # #![feature(try_trait)]
366
+ #[ doc = concat!( "# use std::num::" , stringify!( $Ty) , ";" ) ]
367
+ ///
368
+ /// # fn main() -> Result<(), std::option::NoneError> {
369
+ #[ doc = concat!( "let one = " , stringify!( $Ty) , "::new(1)?;" ) ]
370
+ #[ doc = concat!( "let two = " , stringify!( $Ty) , "::new(2)?;" ) ]
371
+ ///
372
+ /// assert_eq!(two, unsafe { one.unchecked_add(1) });
373
+ /// # Ok(())
374
+ /// # }
375
+ /// ```
376
+ #[ unstable( feature = "nonzero_ops" , issue = "84186" ) ]
377
+ #[ inline]
378
+ pub unsafe fn unchecked_add( self , other: $Int) -> $Ty {
379
+ // SAFETY: The caller ensures there is no overflow.
380
+ unsafe { $Ty:: new_unchecked( self . get( ) . unchecked_add( other) ) }
381
+ }
354
382
}
355
383
) +
356
384
}
0 commit comments