@@ -8,6 +8,7 @@ use crate::convert::Infallible;
88use crate :: fmt;
99use crate :: intrinsics;
1010use crate :: mem;
11+ use crate :: ops:: { BitOr , BitOrAssign } ;
1112use crate :: str:: FromStr ;
1213
1314// 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
110111 }
111112 }
112113
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+
113165 impl_nonzero_fmt! {
114166 #[ $stability] ( Debug , Display , Binary , Octal , LowerHex , UpperHex ) for $Ty
115167 }
0 commit comments