@@ -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
@@ -512,7 +512,7 @@ macro_rules! nonzero_integer {
512
512
fn bitor( self , rhs: Self ) -> Self :: Output {
513
513
// SAFETY: since `self` and `rhs` are both nonzero, the
514
514
// result of the bitwise-or will be nonzero.
515
- unsafe { $Ty :: new_unchecked( self . get( ) | rhs. get( ) ) }
515
+ unsafe { Self :: new_unchecked( self . get( ) | rhs. get( ) ) }
516
516
}
517
517
}
518
518
@@ -524,7 +524,7 @@ macro_rules! nonzero_integer {
524
524
// SAFETY: since `self` is nonzero, the result of the
525
525
// bitwise-or will be nonzero regardless of the value of
526
526
// `rhs`.
527
- unsafe { $Ty :: new_unchecked( self . get( ) | rhs) }
527
+ unsafe { Self :: new_unchecked( self . get( ) | rhs) }
528
528
}
529
529
}
530
530
@@ -536,7 +536,7 @@ macro_rules! nonzero_integer {
536
536
// SAFETY: since `rhs` is nonzero, the result of the
537
537
// bitwise-or will be nonzero regardless of the value of
538
538
// `self`.
539
- unsafe { $Ty :: new_unchecked( self | rhs. get( ) ) }
539
+ unsafe { Self :: new_unchecked( self | rhs. get( ) ) }
540
540
}
541
541
}
542
542
@@ -606,7 +606,7 @@ macro_rules! nonzero_integer_signedness_dependent_impls {
606
606
/// This operation rounds towards zero,
607
607
/// truncating any fractional part of the exact result, and cannot panic.
608
608
#[ inline]
609
- fn div( self , other: $Ty ) -> $Int {
609
+ fn div( self , other: Self ) -> $Int {
610
610
// SAFETY: div by zero is checked because `other` is a nonzero,
611
611
// and MIN/-1 is checked because `self` is an unsigned int.
612
612
unsafe { crate :: intrinsics:: unchecked_div( self , other. get( ) ) }
@@ -618,7 +618,7 @@ macro_rules! nonzero_integer_signedness_dependent_impls {
618
618
type Output = $Int;
619
619
/// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
620
620
#[ inline]
621
- fn rem( self , other: $Ty ) -> $Int {
621
+ fn rem( self , other: Self ) -> $Int {
622
622
// SAFETY: rem by zero is checked because `other` is a nonzero,
623
623
// and MIN/-1 is checked because `self` is an unsigned int.
624
624
unsafe { crate :: intrinsics:: unchecked_rem( self , other. get( ) ) }
@@ -630,12 +630,12 @@ macro_rules! nonzero_integer_signedness_dependent_impls {
630
630
( $Ty: ident signed $Int: ty) => {
631
631
#[ stable( feature = "signed_nonzero_neg" , since = "1.71.0" ) ]
632
632
impl Neg for $Ty {
633
- type Output = $Ty ;
633
+ type Output = Self ;
634
634
635
635
#[ inline]
636
- fn neg( self ) -> $Ty {
636
+ fn neg( self ) -> Self {
637
637
// SAFETY: negation of nonzero cannot yield zero values.
638
- unsafe { $Ty :: new_unchecked( self . get( ) . neg( ) ) }
638
+ unsafe { Self :: new_unchecked( self . get( ) . neg( ) ) }
639
639
}
640
640
}
641
641
@@ -703,7 +703,7 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
703
703
#[ must_use = "this returns the result of the operation, \
704
704
without modifying the original"]
705
705
#[ inline]
706
- pub const fn checked_add( self , other: $Int) -> Option <$Ty > {
706
+ pub const fn checked_add( self , other: $Int) -> Option <Self > {
707
707
if let Some ( result) = self . get( ) . checked_add( other) {
708
708
// SAFETY:
709
709
// - `checked_add` returns `None` on overflow
@@ -712,7 +712,7 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
712
712
// sides to be zero
713
713
//
714
714
// So the result cannot be zero.
715
- Some ( unsafe { $Ty :: new_unchecked( result) } )
715
+ Some ( unsafe { Self :: new_unchecked( result) } )
716
716
} else {
717
717
None
718
718
}
@@ -742,15 +742,15 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
742
742
#[ must_use = "this returns the result of the operation, \
743
743
without modifying the original"]
744
744
#[ inline]
745
- pub const fn saturating_add( self , other: $Int) -> $Ty {
745
+ pub const fn saturating_add( self , other: $Int) -> Self {
746
746
// SAFETY:
747
747
// - `saturating_add` returns `u*::MAX` on overflow, which is non-zero
748
748
// - `self` is non-zero
749
749
// - the only way to get zero from an addition without overflow is for both
750
750
// sides to be zero
751
751
//
752
752
// So the result cannot be zero.
753
- unsafe { $Ty :: new_unchecked( self . get( ) . saturating_add( other) ) }
753
+ unsafe { Self :: new_unchecked( self . get( ) . saturating_add( other) ) }
754
754
}
755
755
756
756
/// Adds an unsigned integer to a non-zero value,
@@ -779,9 +779,9 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
779
779
#[ must_use = "this returns the result of the operation, \
780
780
without modifying the original"]
781
781
#[ inline]
782
- pub const unsafe fn unchecked_add( self , other: $Int) -> $Ty {
782
+ pub const unsafe fn unchecked_add( self , other: $Int) -> Self {
783
783
// SAFETY: The caller ensures there is no overflow.
784
- unsafe { $Ty :: new_unchecked( self . get( ) . unchecked_add( other) ) }
784
+ unsafe { Self :: new_unchecked( self . get( ) . unchecked_add( other) ) }
785
785
}
786
786
787
787
/// Returns the smallest power of two greater than or equal to n.
@@ -812,11 +812,11 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
812
812
#[ must_use = "this returns the result of the operation, \
813
813
without modifying the original"]
814
814
#[ inline]
815
- pub const fn checked_next_power_of_two( self ) -> Option <$Ty > {
815
+ pub const fn checked_next_power_of_two( self ) -> Option <Self > {
816
816
if let Some ( nz) = self . get( ) . checked_next_power_of_two( ) {
817
817
// SAFETY: The next power of two is positive
818
818
// and overflow is checked.
819
- Some ( unsafe { $Ty :: new_unchecked( nz) } )
819
+ Some ( unsafe { Self :: new_unchecked( nz) } )
820
820
} else {
821
821
None
822
822
}
@@ -902,9 +902,9 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
902
902
pub const fn midpoint( self , rhs: Self ) -> Self {
903
903
// SAFETY: The only way to get `0` with midpoint is to have two opposite or
904
904
// 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
905
+ // of the unsignedness of this number and also because `Self` is guaranteed to
906
906
// never being 0.
907
- unsafe { $Ty :: new_unchecked( self . get( ) . midpoint( rhs. get( ) ) ) }
907
+ unsafe { Self :: new_unchecked( self . get( ) . midpoint( rhs. get( ) ) ) }
908
908
}
909
909
910
910
/// Returns `true` if and only if `self == (1 << k)` for some `k`.
@@ -1000,9 +1000,9 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1000
1000
#[ must_use = "this returns the result of the operation, \
1001
1001
without modifying the original"]
1002
1002
#[ inline]
1003
- pub const fn abs( self ) -> $Ty {
1003
+ pub const fn abs( self ) -> Self {
1004
1004
// SAFETY: This cannot overflow to zero.
1005
- unsafe { $Ty :: new_unchecked( self . get( ) . abs( ) ) }
1005
+ unsafe { Self :: new_unchecked( self . get( ) . abs( ) ) }
1006
1006
}
1007
1007
1008
1008
/// Checked absolute value.
@@ -1031,10 +1031,10 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1031
1031
#[ must_use = "this returns the result of the operation, \
1032
1032
without modifying the original"]
1033
1033
#[ inline]
1034
- pub const fn checked_abs( self ) -> Option <$Ty > {
1034
+ pub const fn checked_abs( self ) -> Option <Self > {
1035
1035
if let Some ( nz) = self . get( ) . checked_abs( ) {
1036
1036
// SAFETY: absolute value of nonzero cannot yield zero values.
1037
- Some ( unsafe { $Ty :: new_unchecked( nz) } )
1037
+ Some ( unsafe { Self :: new_unchecked( nz) } )
1038
1038
} else {
1039
1039
None
1040
1040
}
@@ -1066,11 +1066,11 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1066
1066
#[ must_use = "this returns the result of the operation, \
1067
1067
without modifying the original"]
1068
1068
#[ inline]
1069
- pub const fn overflowing_abs( self ) -> ( $Ty , bool ) {
1069
+ pub const fn overflowing_abs( self ) -> ( Self , bool ) {
1070
1070
let ( nz, flag) = self . get( ) . overflowing_abs( ) ;
1071
1071
(
1072
1072
// SAFETY: absolute value of nonzero cannot yield zero values.
1073
- unsafe { $Ty :: new_unchecked( nz) } ,
1073
+ unsafe { Self :: new_unchecked( nz) } ,
1074
1074
flag,
1075
1075
)
1076
1076
}
@@ -1105,9 +1105,9 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1105
1105
#[ must_use = "this returns the result of the operation, \
1106
1106
without modifying the original"]
1107
1107
#[ inline]
1108
- pub const fn saturating_abs( self ) -> $Ty {
1108
+ pub const fn saturating_abs( self ) -> Self {
1109
1109
// SAFETY: absolute value of nonzero cannot yield zero values.
1110
- unsafe { $Ty :: new_unchecked( self . get( ) . saturating_abs( ) ) }
1110
+ unsafe { Self :: new_unchecked( self . get( ) . saturating_abs( ) ) }
1111
1111
}
1112
1112
1113
1113
/// Wrapping absolute value, see
@@ -1138,9 +1138,9 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1138
1138
#[ must_use = "this returns the result of the operation, \
1139
1139
without modifying the original"]
1140
1140
#[ inline]
1141
- pub const fn wrapping_abs( self ) -> $Ty {
1141
+ pub const fn wrapping_abs( self ) -> Self {
1142
1142
// SAFETY: absolute value of nonzero cannot yield zero values.
1143
- unsafe { $Ty :: new_unchecked( self . get( ) . wrapping_abs( ) ) }
1143
+ unsafe { Self :: new_unchecked( self . get( ) . wrapping_abs( ) ) }
1144
1144
}
1145
1145
1146
1146
/// Computes the absolute value of self
@@ -1250,10 +1250,10 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1250
1250
#[ inline]
1251
1251
#[ stable( feature = "nonzero_negation_ops" , since = "1.71.0" ) ]
1252
1252
#[ rustc_const_stable( feature = "nonzero_negation_ops" , since = "1.71.0" ) ]
1253
- pub const fn checked_neg( self ) -> Option <$Ty > {
1253
+ pub const fn checked_neg( self ) -> Option <Self > {
1254
1254
if let Some ( result) = self . get( ) . checked_neg( ) {
1255
1255
// SAFETY: negation of nonzero cannot yield zero values.
1256
- return Some ( unsafe { $Ty :: new_unchecked( result) } ) ;
1256
+ return Some ( unsafe { Self :: new_unchecked( result) } ) ;
1257
1257
}
1258
1258
None
1259
1259
}
@@ -1282,10 +1282,10 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1282
1282
#[ inline]
1283
1283
#[ stable( feature = "nonzero_negation_ops" , since = "1.71.0" ) ]
1284
1284
#[ rustc_const_stable( feature = "nonzero_negation_ops" , since = "1.71.0" ) ]
1285
- pub const fn overflowing_neg( self ) -> ( $Ty , bool ) {
1285
+ pub const fn overflowing_neg( self ) -> ( Self , bool ) {
1286
1286
let ( result, overflow) = self . get( ) . overflowing_neg( ) ;
1287
1287
// SAFETY: negation of nonzero cannot yield zero values.
1288
- ( ( unsafe { $Ty :: new_unchecked( result) } ) , overflow)
1288
+ ( ( unsafe { Self :: new_unchecked( result) } ) , overflow)
1289
1289
}
1290
1290
1291
1291
/// Saturating negation. Computes `-self`,
@@ -1317,11 +1317,11 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1317
1317
#[ inline]
1318
1318
#[ stable( feature = "nonzero_negation_ops" , since = "1.71.0" ) ]
1319
1319
#[ rustc_const_stable( feature = "nonzero_negation_ops" , since = "1.71.0" ) ]
1320
- pub const fn saturating_neg( self ) -> $Ty {
1320
+ pub const fn saturating_neg( self ) -> Self {
1321
1321
if let Some ( result) = self . checked_neg( ) {
1322
1322
return result;
1323
1323
}
1324
- $Ty :: MAX
1324
+ Self :: MAX
1325
1325
}
1326
1326
1327
1327
/// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary
@@ -1349,10 +1349,10 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
1349
1349
#[ inline]
1350
1350
#[ stable( feature = "nonzero_negation_ops" , since = "1.71.0" ) ]
1351
1351
#[ rustc_const_stable( feature = "nonzero_negation_ops" , since = "1.71.0" ) ]
1352
- pub const fn wrapping_neg( self ) -> $Ty {
1352
+ pub const fn wrapping_neg( self ) -> Self {
1353
1353
let result = self . get( ) . wrapping_neg( ) ;
1354
1354
// SAFETY: negation of nonzero cannot yield zero values.
1355
- unsafe { $Ty :: new_unchecked( result) }
1355
+ unsafe { Self :: new_unchecked( result) }
1356
1356
}
1357
1357
} ;
1358
1358
}
0 commit comments