@@ -8,6 +8,7 @@ use crate::convert::Infallible;
8
8
use crate :: fmt;
9
9
use crate :: intrinsics;
10
10
use crate :: mem;
11
+ use crate :: ops:: { BitOr , BitOrAssign } ;
11
12
use crate :: str:: FromStr ;
12
13
13
14
// Used because the `?` operator is not allowed in a const context.
@@ -110,6 +111,57 @@ assert_eq!(size_of::<Option<core::num::", stringify!($Ty), ">>(), size_of::<", s
110
111
}
111
112
}
112
113
114
+ #[ stable( feature = "nonzero_bitor" , since = "1.43.0" ) ]
115
+ impl BitOr for $Ty {
116
+ type Output = Self ;
117
+ #[ inline]
118
+ fn bitor( self , rhs: Self ) -> Self :: Output {
119
+ // Safety: since `self` and `rhs` are both nonzero, the
120
+ // result of the bitwise-or will be nonzero.
121
+ unsafe { $Ty:: new_unchecked( self . get( ) | rhs. get( ) ) }
122
+ }
123
+ }
124
+
125
+ #[ stable( feature = "nonzero_bitor" , since = "1.43.0" ) ]
126
+ impl BitOr <$Int> for $Ty {
127
+ type Output = Self ;
128
+ #[ inline]
129
+ fn bitor( self , rhs: $Int) -> Self :: Output {
130
+ // Safety: since `self` is nonzero, the result of the
131
+ // bitwise-or will be nonzero regardless of the value of
132
+ // `rhs`.
133
+ unsafe { $Ty:: new_unchecked( self . get( ) | rhs) }
134
+ }
135
+ }
136
+
137
+ #[ stable( feature = "nonzero_bitor" , since = "1.43.0" ) ]
138
+ impl BitOr <$Ty> for $Int {
139
+ type Output = $Ty;
140
+ #[ inline]
141
+ fn bitor( self , rhs: $Ty) -> Self :: Output {
142
+ // Safety: since `rhs` is nonzero, the result of the
143
+ // bitwise-or will be nonzero regardless of the value of
144
+ // `self`.
145
+ unsafe { $Ty:: new_unchecked( self | rhs. get( ) ) }
146
+ }
147
+ }
148
+
149
+ #[ stable( feature = "nonzero_bitor" , since = "1.43.0" ) ]
150
+ impl BitOrAssign for $Ty {
151
+ #[ inline]
152
+ fn bitor_assign( & mut self , rhs: Self ) {
153
+ * self = * self | rhs;
154
+ }
155
+ }
156
+
157
+ #[ stable( feature = "nonzero_bitor" , since = "1.43.0" ) ]
158
+ impl BitOrAssign <$Int> for $Ty {
159
+ #[ inline]
160
+ fn bitor_assign( & mut self , rhs: $Int) {
161
+ * self = * self | rhs;
162
+ }
163
+ }
164
+
113
165
impl_nonzero_fmt! {
114
166
#[ $stability] ( Debug , Display , Binary , Octal , LowerHex , UpperHex ) for $Ty
115
167
}
0 commit comments