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