@@ -8,6 +8,7 @@ use crate::marker::{StructuralEq, StructuralPartialEq};
8
8
//
9
9
// Also provides implementations for tuples with lesser arity. For example, tuple_impls!(A B C)
10
10
// will implement everything for (A, B, C), (A, B) and (A,).
11
+ #[ cfg( bootstrap) ]
11
12
macro_rules! tuple_impls {
12
13
// Stopping criteria (1-ary tuple)
13
14
( $T: ident) => {
@@ -142,6 +143,148 @@ macro_rules! tuple_impls {
142
143
}
143
144
}
144
145
146
+ // Recursive macro for implementing n-ary tuple functions and operations
147
+ //
148
+ // Also provides implementations for tuples with lesser arity. For example, tuple_impls!(A B C)
149
+ // will implement everything for (A, B, C), (A, B) and (A,).
150
+ #[ cfg( not( bootstrap) ) ]
151
+ macro_rules! tuple_impls {
152
+ // Stopping criteria (1-ary tuple)
153
+ ( $T: ident) => {
154
+ tuple_impls!( @impl $T) ;
155
+ } ;
156
+ // Running criteria (n-ary tuple, with n >= 2)
157
+ ( $T: ident $( $U: ident ) +) => {
158
+ tuple_impls!( $( $U ) +) ;
159
+ tuple_impls!( @impl $T $( $U ) +) ;
160
+ } ;
161
+ // "Private" internal implementation
162
+ ( @impl $( $T: ident ) +) => {
163
+ maybe_tuple_doc! {
164
+ $( $T) + @
165
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
166
+ impl <$( $T: PartialEq ) ,+> PartialEq for ( $( $T, ) +)
167
+ where
168
+ last_type!( $( $T, ) +) : ?Sized
169
+ {
170
+ #[ inline]
171
+ fn eq( & self , other: & ( $( $T, ) +) ) -> bool {
172
+ $( ${ ignore( $T) } self . ${ index( ) } == other. ${ index( ) } ) &&+
173
+ }
174
+ #[ inline]
175
+ fn ne( & self , other: & ( $( $T, ) +) ) -> bool {
176
+ $( ${ ignore( $T) } self . ${ index( ) } != other. ${ index( ) } ) ||+
177
+ }
178
+ }
179
+ }
180
+
181
+ maybe_tuple_doc! {
182
+ $( $T) + @
183
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
184
+ impl <$( $T: Eq ) ,+> Eq for ( $( $T, ) +)
185
+ where
186
+ last_type!( $( $T, ) +) : ?Sized
187
+ { }
188
+ }
189
+
190
+ maybe_tuple_doc! {
191
+ $( $T) + @
192
+ #[ unstable( feature = "structural_match" , issue = "31434" ) ]
193
+ impl <$( $T: ConstParamTy ) ,+> ConstParamTy for ( $( $T, ) +)
194
+ { }
195
+ }
196
+
197
+ maybe_tuple_doc! {
198
+ $( $T) + @
199
+ #[ unstable( feature = "structural_match" , issue = "31434" ) ]
200
+ impl <$( $T) ,+> StructuralPartialEq for ( $( $T, ) +)
201
+ { }
202
+ }
203
+
204
+ maybe_tuple_doc! {
205
+ $( $T) + @
206
+ #[ unstable( feature = "structural_match" , issue = "31434" ) ]
207
+ impl <$( $T) ,+> StructuralEq for ( $( $T, ) +)
208
+ { }
209
+ }
210
+
211
+ maybe_tuple_doc! {
212
+ $( $T) + @
213
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
214
+ impl <$( $T: PartialOrd ) ,+> PartialOrd for ( $( $T, ) +)
215
+ where
216
+ last_type!( $( $T, ) +) : ?Sized
217
+ {
218
+ #[ inline]
219
+ fn partial_cmp( & self , other: & ( $( $T, ) +) ) -> Option <Ordering > {
220
+ lexical_partial_cmp!( $( ${ ignore( $T) } self . ${ index( ) } , other. ${ index( ) } ) ,+)
221
+ }
222
+ #[ inline]
223
+ fn lt( & self , other: & ( $( $T, ) +) ) -> bool {
224
+ lexical_ord!( lt, Less , $( ${ ignore( $T) } self . ${ index( ) } , other. ${ index( ) } ) ,+)
225
+ }
226
+ #[ inline]
227
+ fn le( & self , other: & ( $( $T, ) +) ) -> bool {
228
+ lexical_ord!( le, Less , $( ${ ignore( $T) } self . ${ index( ) } , other. ${ index( ) } ) ,+)
229
+ }
230
+ #[ inline]
231
+ fn ge( & self , other: & ( $( $T, ) +) ) -> bool {
232
+ lexical_ord!( ge, Greater , $( ${ ignore( $T) } self . ${ index( ) } , other. ${ index( ) } ) ,+)
233
+ }
234
+ #[ inline]
235
+ fn gt( & self , other: & ( $( $T, ) +) ) -> bool {
236
+ lexical_ord!( gt, Greater , $( ${ ignore( $T) } self . ${ index( ) } , other. ${ index( ) } ) ,+)
237
+ }
238
+ }
239
+ }
240
+
241
+ maybe_tuple_doc! {
242
+ $( $T) + @
243
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
244
+ impl <$( $T: Ord ) ,+> Ord for ( $( $T, ) +)
245
+ where
246
+ last_type!( $( $T, ) +) : ?Sized
247
+ {
248
+ #[ inline]
249
+ fn cmp( & self , other: & ( $( $T, ) +) ) -> Ordering {
250
+ lexical_cmp!( $( ${ ignore( $T) } self . ${ index( ) } , other. ${ index( ) } ) ,+)
251
+ }
252
+ }
253
+ }
254
+
255
+ maybe_tuple_doc! {
256
+ $( $T) + @
257
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
258
+ impl <$( $T: Default ) ,+> Default for ( $( $T, ) +) {
259
+ #[ inline]
260
+ fn default ( ) -> ( $( $T, ) +) {
261
+ ( $( { let x: $T = Default :: default ( ) ; x} , ) +)
262
+ }
263
+ }
264
+ }
265
+
266
+ #[ stable( feature = "array_tuple_conv" , since = "1.71.0" ) ]
267
+ impl <T > From <[ T ; ${ count( $T) } ] > for ( $( ${ ignore( $T) } T , ) +) {
268
+ #[ inline]
269
+ #[ allow( non_snake_case) ]
270
+ fn from( array: [ T ; ${ count( $T) } ] ) -> Self {
271
+ let [ $( $T, ) +] = array;
272
+ ( $( $T, ) +)
273
+ }
274
+ }
275
+
276
+ #[ stable( feature = "array_tuple_conv" , since = "1.71.0" ) ]
277
+ impl <T > From <( $( ${ ignore( $T) } T , ) +) > for [ T ; ${ count( $T) } ] {
278
+ #[ inline]
279
+ #[ allow( non_snake_case) ]
280
+ fn from( tuple: ( $( ${ ignore( $T) } T , ) +) ) -> Self {
281
+ let ( $( $T, ) +) = tuple;
282
+ [ $( $T, ) +]
283
+ }
284
+ }
285
+ }
286
+ }
287
+
145
288
// If this is a unary tuple, it adds a doc comment.
146
289
// Otherwise, it hides the docs entirely.
147
290
macro_rules! maybe_tuple_doc {
0 commit comments