Skip to content

Commit fdc56b6

Browse files
committed
doc: add note before panicking examples for strict_overflow_ops
1 parent 62fb0db commit fdc56b6

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

library/core/src/num/int_macros.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ macro_rules! int_impl {
472472
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).strict_add(1), ", stringify!($SelfT), "::MAX - 1);")]
473473
/// ```
474474
///
475+
/// The following panics because of overflow:
476+
///
475477
/// ```should_panic
476478
/// #![feature(strict_overflow_ops)]
477479
#[doc = concat!("let _ = (", stringify!($SelfT), "::MAX - 2).strict_add(3);")]
@@ -552,6 +554,8 @@ macro_rules! int_impl {
552554
#[doc = concat!("assert_eq!(1", stringify!($SelfT), ".strict_add_unsigned(2), 3);")]
553555
/// ```
554556
///
557+
/// The following panics because of overflow:
558+
///
555559
/// ```should_panic
556560
/// #![feature(strict_overflow_ops)]
557561
#[doc = concat!("let _ = (", stringify!($SelfT), "::MAX - 2).strict_add_unsigned(3);")]
@@ -606,6 +610,8 @@ macro_rules! int_impl {
606610
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 2).strict_sub(1), ", stringify!($SelfT), "::MIN + 1);")]
607611
/// ```
608612
///
613+
/// The following panics because of overflow:
614+
///
609615
/// ```should_panic
610616
/// #![feature(strict_overflow_ops)]
611617
#[doc = concat!("let _ = (", stringify!($SelfT), "::MIN + 2).strict_sub(3);")]
@@ -686,6 +692,8 @@ macro_rules! int_impl {
686692
#[doc = concat!("assert_eq!(1", stringify!($SelfT), ".strict_sub_unsigned(2), -1);")]
687693
/// ```
688694
///
695+
/// The following panics because of overflow:
696+
///
689697
/// ```should_panic
690698
/// #![feature(strict_overflow_ops)]
691699
#[doc = concat!("let _ = (", stringify!($SelfT), "::MIN + 2).strict_sub_unsigned(3);")]
@@ -740,6 +748,8 @@ macro_rules! int_impl {
740748
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.strict_mul(1), ", stringify!($SelfT), "::MAX);")]
741749
/// ```
742750
///
751+
/// The following panics because of overflow:
752+
///
743753
/// ``` should_panic
744754
/// #![feature(strict_overflow_ops)]
745755
#[doc = concat!("let _ = ", stringify!($SelfT), "::MAX.strict_mul(2);")]
@@ -831,11 +841,15 @@ macro_rules! int_impl {
831841
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).strict_div(-1), ", stringify!($Max), ");")]
832842
/// ```
833843
///
844+
/// The following panics because of overflow:
845+
///
834846
/// ```should_panic
835847
/// #![feature(strict_overflow_ops)]
836848
#[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_div(-1);")]
837849
/// ```
838850
///
851+
/// The following panics because of division by zero:
852+
///
839853
/// ```should_panic
840854
/// #![feature(strict_overflow_ops)]
841855
#[doc = concat!("let _ = (1", stringify!($SelfT), ").strict_div(0);")]
@@ -901,11 +915,15 @@ macro_rules! int_impl {
901915
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).strict_div_euclid(-1), ", stringify!($Max), ");")]
902916
/// ```
903917
///
918+
/// The following panics because of overflow:
919+
///
904920
/// ```should_panic
905921
/// #![feature(strict_overflow_ops)]
906922
#[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_div_euclid(-1);")]
907923
/// ```
908924
///
925+
/// The following panics because of division by zero:
926+
///
909927
/// ```should_panic
910928
/// #![feature(strict_overflow_ops)]
911929
#[doc = concat!("let _ = (1", stringify!($SelfT), ").strict_div_euclid(0);")]
@@ -970,11 +988,15 @@ macro_rules! int_impl {
970988
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".strict_rem(2), 1);")]
971989
/// ```
972990
///
991+
/// The following panics because of division by zero:
992+
///
973993
/// ```should_panic
974994
/// #![feature(strict_overflow_ops)]
975995
#[doc = concat!("let _ = 5", stringify!($SelfT), ".strict_rem(0);")]
976996
/// ```
977997
///
998+
/// The following panics because of overflow:
999+
///
9781000
/// ```should_panic
9791001
/// #![feature(strict_overflow_ops)]
9801002
#[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_rem(-1);")]
@@ -1039,11 +1061,15 @@ macro_rules! int_impl {
10391061
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".strict_rem_euclid(2), 1);")]
10401062
/// ```
10411063
///
1064+
/// The following panics because of division by zero:
1065+
///
10421066
/// ```should_panic
10431067
/// #![feature(strict_overflow_ops)]
10441068
#[doc = concat!("let _ = 5", stringify!($SelfT), ".strict_rem_euclid(0);")]
10451069
/// ```
10461070
///
1071+
/// The following panics because of overflow:
1072+
///
10471073
/// ```should_panic
10481074
/// #![feature(strict_overflow_ops)]
10491075
#[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_rem_euclid(-1);")]
@@ -1121,6 +1147,8 @@ macro_rules! int_impl {
11211147
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".strict_neg(), -5);")]
11221148
/// ```
11231149
///
1150+
/// The following panics because of overflow:
1151+
///
11241152
/// ```should_panic
11251153
/// #![feature(strict_overflow_ops)]
11261154
#[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_neg();")]
@@ -1175,6 +1203,8 @@ macro_rules! int_impl {
11751203
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".strict_shl(4), 0x10);")]
11761204
/// ```
11771205
///
1206+
/// The following panics because of overflow:
1207+
///
11781208
/// ```should_panic
11791209
/// #![feature(strict_overflow_ops)]
11801210
#[doc = concat!("let _ = 0x1", stringify!($SelfT), ".strict_shl(129);")]
@@ -1256,6 +1286,8 @@ macro_rules! int_impl {
12561286
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".strict_shr(4), 0x1);")]
12571287
/// ```
12581288
///
1289+
/// The following panics because of overflow:
1290+
///
12591291
/// ```should_panic
12601292
/// #![feature(strict_overflow_ops)]
12611293
#[doc = concat!("let _ = 0x10", stringify!($SelfT), ".strict_shr(128);")]
@@ -1340,6 +1372,8 @@ macro_rules! int_impl {
13401372
#[doc = concat!("assert_eq!((-5", stringify!($SelfT), ").strict_abs(), 5);")]
13411373
/// ```
13421374
///
1375+
/// The following panics because of overflow:
1376+
///
13431377
/// ```should_panic
13441378
/// #![feature(strict_overflow_ops)]
13451379
#[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_abs();")]
@@ -1414,6 +1448,8 @@ macro_rules! int_impl {
14141448
#[doc = concat!("assert_eq!(8", stringify!($SelfT), ".strict_pow(2), 64);")]
14151449
/// ```
14161450
///
1451+
/// The following panics because of overflow:
1452+
///
14171453
/// ```should_panic
14181454
/// #![feature(strict_overflow_ops)]
14191455
#[doc = concat!("let _ = ", stringify!($SelfT), "::MAX.strict_pow(2);")]

library/core/src/num/uint_macros.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ macro_rules! uint_impl {
480480
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).strict_add(1), ", stringify!($SelfT), "::MAX - 1);")]
481481
/// ```
482482
///
483+
/// The following panics because of overflow:
484+
///
483485
/// ```should_panic
484486
/// #![feature(strict_overflow_ops)]
485487
#[doc = concat!("let _ = (", stringify!($SelfT), "::MAX - 2).strict_add(3);")]
@@ -561,6 +563,8 @@ macro_rules! uint_impl {
561563
#[doc = concat!("assert_eq!(1", stringify!($SelfT), ".strict_add_signed(2), 3);")]
562564
/// ```
563565
///
566+
/// The following panic because of overflow:
567+
///
564568
/// ```should_panic
565569
/// #![feature(strict_overflow_ops)]
566570
#[doc = concat!("let _ = 1", stringify!($SelfT), ".strict_add_signed(-2);")]
@@ -620,6 +624,8 @@ macro_rules! uint_impl {
620624
#[doc = concat!("assert_eq!(1", stringify!($SelfT), ".strict_sub(1), 0);")]
621625
/// ```
622626
///
627+
/// The following panics because of overflow:
628+
///
623629
/// ```should_panic
624630
/// #![feature(strict_overflow_ops)]
625631
#[doc = concat!("let _ = 0", stringify!($SelfT), ".strict_sub(1);")]
@@ -700,6 +706,8 @@ macro_rules! uint_impl {
700706
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".strict_mul(1), 5);")]
701707
/// ```
702708
///
709+
/// The following panics because of overflow:
710+
///
703711
/// ``` should_panic
704712
/// #![feature(strict_overflow_ops)]
705713
#[doc = concat!("let _ = ", stringify!($SelfT), "::MAX.strict_mul(2);")]
@@ -1172,6 +1180,8 @@ macro_rules! uint_impl {
11721180
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".strict_neg(), 0);")]
11731181
/// ```
11741182
///
1183+
/// The following panics because of overflow:
1184+
///
11751185
/// ```should_panic
11761186
/// #![feature(strict_overflow_ops)]
11771187
#[doc = concat!("let _ = 1", stringify!($SelfT), ".strict_neg();")]
@@ -1226,6 +1236,8 @@ macro_rules! uint_impl {
12261236
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".strict_shl(4), 0x10);")]
12271237
/// ```
12281238
///
1239+
/// The following panics because of overflow:
1240+
///
12291241
/// ```should_panic
12301242
/// #![feature(strict_overflow_ops)]
12311243
#[doc = concat!("let _ = 0x10", stringify!($SelfT), ".strict_shl(129);")]
@@ -1307,6 +1319,8 @@ macro_rules! uint_impl {
13071319
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".strict_shr(4), 0x1);")]
13081320
/// ```
13091321
///
1322+
/// The following panics because of overflow:
1323+
///
13101324
/// ```should_panic
13111325
/// #![feature(strict_overflow_ops)]
13121326
#[doc = concat!("let _ = 0x10", stringify!($SelfT), ".strict_shr(129);")]
@@ -1406,6 +1420,8 @@ macro_rules! uint_impl {
14061420
#[doc = concat!("assert_eq!(2", stringify!($SelfT), ".strict_pow(5), 32);")]
14071421
/// ```
14081422
///
1423+
/// The following panics because of overflow:
1424+
///
14091425
/// ```should_panic
14101426
/// #![feature(strict_overflow_ops)]
14111427
#[doc = concat!("let _ = ", stringify!($SelfT), "::MAX.strict_pow(2);")]

0 commit comments

Comments
 (0)