@@ -456,9 +456,13 @@ pub trait Div<Rhs = Self> {
456
456
}
457
457
458
458
macro_rules! div_impl_integer {
459
- ( $( $ t: ty) * ) => ( $(
459
+ ( $( ( $ ( $ t: ty) * ) => $panic : expr ) , * ) => ( $ ( $(
460
460
/// This operation rounds towards zero, truncating any
461
461
/// fractional part of the exact result.
462
+ ///
463
+ /// # Panics
464
+ ///
465
+ #[ doc = $panic]
462
466
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
463
467
impl Div for $t {
464
468
type Output = $t;
@@ -468,10 +472,13 @@ macro_rules! div_impl_integer {
468
472
}
469
473
470
474
forward_ref_binop! { impl Div , div for $t, $t }
471
- ) * )
475
+ ) * ) * )
472
476
}
473
477
474
- div_impl_integer ! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
478
+ div_impl_integer ! {
479
+ ( usize u8 u16 u32 u64 u128 ) => "This operation will panic if `other == 0`." ,
480
+ ( isize i8 i16 i32 i64 i128 ) => "This operation will panic if `other == 0` or the division results in overflow."
481
+ }
475
482
476
483
macro_rules! div_impl_float {
477
484
( $( $t: ty) * ) => ( $(
@@ -549,9 +556,13 @@ pub trait Rem<Rhs = Self> {
549
556
}
550
557
551
558
macro_rules! rem_impl_integer {
552
- ( $( $ t: ty) * ) => ( $(
559
+ ( $( ( $ ( $ t: ty) * ) => $panic : expr ) , * ) => ( $ ( $(
553
560
/// This operation satisfies `n % d == n - (n / d) * d`. The
554
561
/// result has the same sign as the left operand.
562
+ ///
563
+ /// # Panics
564
+ ///
565
+ #[ doc = $panic]
555
566
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
556
567
impl Rem for $t {
557
568
type Output = $t;
@@ -561,10 +572,13 @@ macro_rules! rem_impl_integer {
561
572
}
562
573
563
574
forward_ref_binop! { impl Rem , rem for $t, $t }
564
- ) * )
575
+ ) * ) * )
565
576
}
566
577
567
- rem_impl_integer ! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
578
+ rem_impl_integer ! {
579
+ ( usize u8 u16 u32 u64 u128 ) => "This operation will panic if `other == 0`." ,
580
+ ( isize i8 i16 i32 i64 i128 ) => "This operation will panic if `other == 0` or if `self / other` results in overflow."
581
+ }
568
582
569
583
macro_rules! rem_impl_float {
570
584
( $( $t: ty) * ) => ( $(
0 commit comments