@@ -317,7 +317,7 @@ macro_rules! nonzero_integer {
317
317
#[ must_use = "this returns the result of the operation, \
318
318
without modifying the original"]
319
319
#[ inline]
320
- pub const fn checked_mul( self , other: $Ty ) -> Option <$Ty > {
320
+ pub const fn checked_mul( self , other: Self ) -> Option <Self > {
321
321
if let Some ( result) = self . get( ) . checked_mul( other. get( ) ) {
322
322
// SAFETY:
323
323
// - `checked_mul` returns `None` on overflow
@@ -326,7 +326,7 @@ macro_rules! nonzero_integer {
326
326
// of the sides to be zero
327
327
//
328
328
// So the result cannot be zero.
329
- Some ( unsafe { $Ty :: new_unchecked( result) } )
329
+ Some ( unsafe { Self :: new_unchecked( result) } )
330
330
} else {
331
331
None
332
332
}
@@ -356,7 +356,7 @@ macro_rules! nonzero_integer {
356
356
#[ must_use = "this returns the result of the operation, \
357
357
without modifying the original"]
358
358
#[ inline]
359
- pub const fn saturating_mul( self , other: $Ty ) -> $Ty {
359
+ pub const fn saturating_mul( self , other: Self ) -> Self {
360
360
// SAFETY:
361
361
// - `saturating_mul` returns `u*::MAX`/`i*::MAX`/`i*::MIN` on overflow/underflow,
362
362
// all of which are non-zero
@@ -365,7 +365,7 @@ macro_rules! nonzero_integer {
365
365
// of the sides to be zero
366
366
//
367
367
// So the result cannot be zero.
368
- unsafe { $Ty :: new_unchecked( self . get( ) . saturating_mul( other. get( ) ) ) }
368
+ unsafe { Self :: new_unchecked( self . get( ) . saturating_mul( other. get( ) ) ) }
369
369
}
370
370
371
371
/// Multiplies two non-zero integers together,
@@ -403,9 +403,9 @@ macro_rules! nonzero_integer {
403
403
#[ must_use = "this returns the result of the operation, \
404
404
without modifying the original"]
405
405
#[ inline]
406
- pub const unsafe fn unchecked_mul( self , other: $Ty ) -> $Ty {
406
+ pub const unsafe fn unchecked_mul( self , other: Self ) -> Self {
407
407
// SAFETY: The caller ensures there is no overflow.
408
- unsafe { $Ty :: new_unchecked( self . get( ) . unchecked_mul( other. get( ) ) ) }
408
+ unsafe { Self :: new_unchecked( self . get( ) . unchecked_mul( other. get( ) ) ) }
409
409
}
410
410
411
411
/// Raises non-zero value to an integer power.
@@ -433,7 +433,7 @@ macro_rules! nonzero_integer {
433
433
#[ must_use = "this returns the result of the operation, \
434
434
without modifying the original"]
435
435
#[ inline]
436
- pub const fn checked_pow( self , other: u32 ) -> Option <$Ty > {
436
+ pub const fn checked_pow( self , other: u32 ) -> Option <Self > {
437
437
if let Some ( result) = self . get( ) . checked_pow( other) {
438
438
// SAFETY:
439
439
// - `checked_pow` returns `None` on overflow/underflow
@@ -442,7 +442,7 @@ macro_rules! nonzero_integer {
442
442
// for base to be zero
443
443
//
444
444
// So the result cannot be zero.
445
- Some ( unsafe { $Ty :: new_unchecked( result) } )
445
+ Some ( unsafe { Self :: new_unchecked( result) } )
446
446
} else {
447
447
None
448
448
}
@@ -481,7 +481,7 @@ macro_rules! nonzero_integer {
481
481
#[ must_use = "this returns the result of the operation, \
482
482
without modifying the original"]
483
483
#[ inline]
484
- pub const fn saturating_pow( self , other: u32 ) -> $Ty {
484
+ pub const fn saturating_pow( self , other: u32 ) -> Self {
485
485
// SAFETY:
486
486
// - `saturating_pow` returns `u*::MAX`/`i*::MAX`/`i*::MIN` on overflow/underflow,
487
487
// all of which are non-zero
@@ -490,7 +490,7 @@ macro_rules! nonzero_integer {
490
490
// for base to be zero
491
491
//
492
492
// So the result cannot be zero.
493
- unsafe { $Ty :: new_unchecked( self . get( ) . saturating_pow( other) ) }
493
+ unsafe { Self :: new_unchecked( self . get( ) . saturating_pow( other) ) }
494
494
}
495
495
}
496
496
@@ -508,29 +508,32 @@ macro_rules! nonzero_integer {
508
508
#[ stable( feature = "nonzero_bitor" , since = "1.45.0" ) ]
509
509
impl BitOr for $Ty {
510
510
type Output = Self ;
511
+
511
512
#[ inline]
512
513
fn bitor( self , rhs: Self ) -> Self :: Output {
513
514
// SAFETY: since `self` and `rhs` are both nonzero, the
514
515
// result of the bitwise-or will be nonzero.
515
- unsafe { $Ty :: new_unchecked( self . get( ) | rhs. get( ) ) }
516
+ unsafe { Self :: new_unchecked( self . get( ) | rhs. get( ) ) }
516
517
}
517
518
}
518
519
519
520
#[ stable( feature = "nonzero_bitor" , since = "1.45.0" ) ]
520
521
impl BitOr <$Int> for $Ty {
521
522
type Output = Self ;
523
+
522
524
#[ inline]
523
525
fn bitor( self , rhs: $Int) -> Self :: Output {
524
526
// SAFETY: since `self` is nonzero, the result of the
525
527
// bitwise-or will be nonzero regardless of the value of
526
528
// `rhs`.
527
- unsafe { $Ty :: new_unchecked( self . get( ) | rhs) }
529
+ unsafe { Self :: new_unchecked( self . get( ) | rhs) }
528
530
}
529
531
}
530
532
531
533
#[ stable( feature = "nonzero_bitor" , since = "1.45.0" ) ]
532
534
impl BitOr <$Ty> for $Int {
533
535
type Output = $Ty;
536
+
534
537
#[ inline]
535
538
fn bitor( self , rhs: $Ty) -> Self :: Output {
536
539
// SAFETY: since `rhs` is nonzero, the result of the
@@ -603,6 +606,7 @@ macro_rules! nonzero_integer_signedness_dependent_impls {
603
606
#[ stable( feature = "nonzero_div" , since = "1.51.0" ) ]
604
607
impl Div <$Ty> for $Int {
605
608
type Output = $Int;
609
+
606
610
/// This operation rounds towards zero,
607
611
/// truncating any fractional part of the exact result, and cannot panic.
608
612
#[ inline]
@@ -616,6 +620,7 @@ macro_rules! nonzero_integer_signedness_dependent_impls {
616
620
#[ stable( feature = "nonzero_div" , since = "1.51.0" ) ]
617
621
impl Rem <$Ty> for $Int {
618
622
type Output = $Int;
623
+
619
624
/// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
620
625
#[ inline]
621
626
fn rem( self , other: $Ty) -> $Int {
@@ -630,12 +635,12 @@ macro_rules! nonzero_integer_signedness_dependent_impls {
630
635
( $Ty: ident signed $Int: ty) => {
631
636
#[ stable( feature = "signed_nonzero_neg" , since = "1.71.0" ) ]
632
637
impl Neg for $Ty {
633
- type Output = $Ty ;
638
+ type Output = Self ;
634
639
635
640
#[ inline]
636
- fn neg( self ) -> $Ty {
641
+ fn neg( self ) -> Self {
637
642
// SAFETY: negation of nonzero cannot yield zero values.
638
- unsafe { $Ty :: new_unchecked( self . get( ) . neg( ) ) }
643
+ unsafe { Self :: new_unchecked( self . get( ) . neg( ) ) }
639
644
}
640
645
}
641
646
@@ -703,7 +708,7 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
703
708
#[ must_use = "this returns the result of the operation, \
704
709
without modifying the original"]
705
710
#[ inline]
706
- pub const fn checked_add( self , other: $Int) -> Option <$Ty > {
711
+ pub const fn checked_add( self , other: $Int) -> Option <Self > {
707
712
if let Some ( result) = self . get( ) . checked_add( other) {
708
713
// SAFETY:
709
714
// - `checked_add` returns `None` on overflow
@@ -712,7 +717,7 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
712
717
// sides to be zero
713
718
//
714
719
// So the result cannot be zero.
715
- Some ( unsafe { $Ty :: new_unchecked( result) } )
720
+ Some ( unsafe { Self :: new_unchecked( result) } )
716
721
} else {
717
722
None
718
723
}
@@ -742,15 +747,15 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
742
747
#[ must_use = "this returns the result of the operation, \
743
748
without modifying the original"]
744
749
#[ inline]
745
- pub const fn saturating_add( self , other: $Int) -> $Ty {
750
+ pub const fn saturating_add( self , other: $Int) -> Self {
746
751
// SAFETY:
747
752
// - `saturating_add` returns `u*::MAX` on overflow, which is non-zero
748
753
// - `self` is non-zero
749
754
// - the only way to get zero from an addition without overflow is for both
750
755
// sides to be zero
751
756
//
752
757
// So the result cannot be zero.
753
- unsafe { $Ty :: new_unchecked( self . get( ) . saturating_add( other) ) }
758
+ unsafe { Self :: new_unchecked( self . get( ) . saturating_add( other) ) }
754
759
}
755
760
756
761
/// Adds an unsigned integer to a non-zero value,
@@ -779,9 +784,9 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
779
784
#[ must_use = "this returns the result of the operation, \
780
785
without modifying the original"]
781
786
#[ inline]
782
- pub const unsafe fn unchecked_add( self , other: $Int) -> $Ty {
787
+ pub const unsafe fn unchecked_add( self , other: $Int) -> Self {
783
788
// SAFETY: The caller ensures there is no overflow.
784
- unsafe { $Ty :: new_unchecked( self . get( ) . unchecked_add( other) ) }
789
+ unsafe { Self :: new_unchecked( self . get( ) . unchecked_add( other) ) }
785
790
}
786
791
787
792
/// Returns the smallest power of two greater than or equal to n.
@@ -812,11 +817,11 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
812
817
#[ must_use = "this returns the result of the operation, \
813
818
without modifying the original"]
814
819
#[ inline]
815
- pub const fn checked_next_power_of_two( self ) -> Option <$Ty > {
820
+ pub const fn checked_next_power_of_two( self ) -> Option <Self > {
816
821
if let Some ( nz) = self . get( ) . checked_next_power_of_two( ) {
817
822
// SAFETY: The next power of two is positive
818
823
// and overflow is checked.
819
- Some ( unsafe { $Ty :: new_unchecked( nz) } )
824
+ Some ( unsafe { Self :: new_unchecked( nz) } )
820
825
} else {
821
826
None
822
827
}
@@ -902,9 +907,9 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
902
907
pub const fn midpoint( self , rhs: Self ) -> Self {
903
908
// SAFETY: The only way to get `0` with midpoint is to have two opposite or
904
909
// near opposite numbers: (-5, 5), (0, 1), (0, 0) which is impossible because
905
- // of the unsignedness of this number and also because $Ty is guaranteed to
910
+ // of the unsignedness of this number and also because `Self` is guaranteed to
906
911
// never being 0.
907
- unsafe { $Ty :: new_unchecked( self . get( ) . midpoint( rhs. get( ) ) ) }
912
+ unsafe { Self :: new_unchecked( self . get( ) . midpoint( rhs. get( ) ) ) }
908
913
}
909
914
910
915
/// Returns `true` if and only if `self == (1 << k)` for some `k`.
@@ -1000,9 +1005,9 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1000
1005
#[ must_use = "this returns the result of the operation, \
1001
1006
without modifying the original"]
1002
1007
#[ inline]
1003
- pub const fn abs( self ) -> $Ty {
1008
+ pub const fn abs( self ) -> Self {
1004
1009
// SAFETY: This cannot overflow to zero.
1005
- unsafe { $Ty :: new_unchecked( self . get( ) . abs( ) ) }
1010
+ unsafe { Self :: new_unchecked( self . get( ) . abs( ) ) }
1006
1011
}
1007
1012
1008
1013
/// Checked absolute value.
@@ -1031,10 +1036,10 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1031
1036
#[ must_use = "this returns the result of the operation, \
1032
1037
without modifying the original"]
1033
1038
#[ inline]
1034
- pub const fn checked_abs( self ) -> Option <$Ty > {
1039
+ pub const fn checked_abs( self ) -> Option <Self > {
1035
1040
if let Some ( nz) = self . get( ) . checked_abs( ) {
1036
1041
// SAFETY: absolute value of nonzero cannot yield zero values.
1037
- Some ( unsafe { $Ty :: new_unchecked( nz) } )
1042
+ Some ( unsafe { Self :: new_unchecked( nz) } )
1038
1043
} else {
1039
1044
None
1040
1045
}
@@ -1066,11 +1071,11 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1066
1071
#[ must_use = "this returns the result of the operation, \
1067
1072
without modifying the original"]
1068
1073
#[ inline]
1069
- pub const fn overflowing_abs( self ) -> ( $Ty , bool ) {
1074
+ pub const fn overflowing_abs( self ) -> ( Self , bool ) {
1070
1075
let ( nz, flag) = self . get( ) . overflowing_abs( ) ;
1071
1076
(
1072
1077
// SAFETY: absolute value of nonzero cannot yield zero values.
1073
- unsafe { $Ty :: new_unchecked( nz) } ,
1078
+ unsafe { Self :: new_unchecked( nz) } ,
1074
1079
flag,
1075
1080
)
1076
1081
}
@@ -1105,9 +1110,9 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1105
1110
#[ must_use = "this returns the result of the operation, \
1106
1111
without modifying the original"]
1107
1112
#[ inline]
1108
- pub const fn saturating_abs( self ) -> $Ty {
1113
+ pub const fn saturating_abs( self ) -> Self {
1109
1114
// SAFETY: absolute value of nonzero cannot yield zero values.
1110
- unsafe { $Ty :: new_unchecked( self . get( ) . saturating_abs( ) ) }
1115
+ unsafe { Self :: new_unchecked( self . get( ) . saturating_abs( ) ) }
1111
1116
}
1112
1117
1113
1118
/// Wrapping absolute value, see
@@ -1138,9 +1143,9 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1138
1143
#[ must_use = "this returns the result of the operation, \
1139
1144
without modifying the original"]
1140
1145
#[ inline]
1141
- pub const fn wrapping_abs( self ) -> $Ty {
1146
+ pub const fn wrapping_abs( self ) -> Self {
1142
1147
// SAFETY: absolute value of nonzero cannot yield zero values.
1143
- unsafe { $Ty :: new_unchecked( self . get( ) . wrapping_abs( ) ) }
1148
+ unsafe { Self :: new_unchecked( self . get( ) . wrapping_abs( ) ) }
1144
1149
}
1145
1150
1146
1151
/// Computes the absolute value of self
@@ -1250,10 +1255,10 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1250
1255
#[ inline]
1251
1256
#[ stable( feature = "nonzero_negation_ops" , since = "1.71.0" ) ]
1252
1257
#[ rustc_const_stable( feature = "nonzero_negation_ops" , since = "1.71.0" ) ]
1253
- pub const fn checked_neg( self ) -> Option <$Ty > {
1258
+ pub const fn checked_neg( self ) -> Option <Self > {
1254
1259
if let Some ( result) = self . get( ) . checked_neg( ) {
1255
1260
// SAFETY: negation of nonzero cannot yield zero values.
1256
- return Some ( unsafe { $Ty :: new_unchecked( result) } ) ;
1261
+ return Some ( unsafe { Self :: new_unchecked( result) } ) ;
1257
1262
}
1258
1263
None
1259
1264
}
@@ -1282,10 +1287,10 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1282
1287
#[ inline]
1283
1288
#[ stable( feature = "nonzero_negation_ops" , since = "1.71.0" ) ]
1284
1289
#[ rustc_const_stable( feature = "nonzero_negation_ops" , since = "1.71.0" ) ]
1285
- pub const fn overflowing_neg( self ) -> ( $Ty , bool ) {
1290
+ pub const fn overflowing_neg( self ) -> ( Self , bool ) {
1286
1291
let ( result, overflow) = self . get( ) . overflowing_neg( ) ;
1287
1292
// SAFETY: negation of nonzero cannot yield zero values.
1288
- ( ( unsafe { $Ty :: new_unchecked( result) } ) , overflow)
1293
+ ( ( unsafe { Self :: new_unchecked( result) } ) , overflow)
1289
1294
}
1290
1295
1291
1296
/// Saturating negation. Computes `-self`,
@@ -1317,11 +1322,11 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1317
1322
#[ inline]
1318
1323
#[ stable( feature = "nonzero_negation_ops" , since = "1.71.0" ) ]
1319
1324
#[ rustc_const_stable( feature = "nonzero_negation_ops" , since = "1.71.0" ) ]
1320
- pub const fn saturating_neg( self ) -> $Ty {
1325
+ pub const fn saturating_neg( self ) -> Self {
1321
1326
if let Some ( result) = self . checked_neg( ) {
1322
1327
return result;
1323
1328
}
1324
- $Ty :: MAX
1329
+ Self :: MAX
1325
1330
}
1326
1331
1327
1332
/// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary
@@ -1349,10 +1354,10 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1349
1354
#[ inline]
1350
1355
#[ stable( feature = "nonzero_negation_ops" , since = "1.71.0" ) ]
1351
1356
#[ rustc_const_stable( feature = "nonzero_negation_ops" , since = "1.71.0" ) ]
1352
- pub const fn wrapping_neg( self ) -> $Ty {
1357
+ pub const fn wrapping_neg( self ) -> Self {
1353
1358
let result = self . get( ) . wrapping_neg( ) ;
1354
1359
// SAFETY: negation of nonzero cannot yield zero values.
1355
- unsafe { $Ty :: new_unchecked( result) }
1360
+ unsafe { Self :: new_unchecked( result) }
1356
1361
}
1357
1362
} ;
1358
1363
}
0 commit comments