@@ -233,10 +233,137 @@ pub trait DerivesCopy {
233
233
fn derives_copy ( & self , lib : & Library ) -> bool ;
234
234
}
235
235
236
- impl < T : IsIncomplete > DerivesCopy for T {
236
+ impl DerivesCopy for Fundamental {
237
237
fn derives_copy ( & self , lib : & Library ) -> bool {
238
- // Copy is derived for all complete types.
239
- !self . is_incomplete ( lib)
238
+ if self . is_incomplete ( lib) {
239
+ return false ;
240
+ }
241
+
242
+ // None of the pointer types
243
+ !matches ! (
244
+ self ,
245
+ Fundamental :: Pointer
246
+ | Fundamental :: VarArgs
247
+ | Fundamental :: Utf8
248
+ | Fundamental :: Filename
249
+ | Fundamental :: IntPtr
250
+ | Fundamental :: UIntPtr
251
+ | Fundamental :: OsString
252
+ | Fundamental :: Unsupported
253
+ )
254
+ }
255
+ }
256
+
257
+ impl DerivesCopy for Alias {
258
+ fn derives_copy ( & self , lib : & Library ) -> bool {
259
+ if self . is_incomplete ( lib) {
260
+ return false ;
261
+ }
262
+
263
+ !self . is_ptr ( )
264
+ }
265
+ }
266
+
267
+ impl DerivesCopy for Field {
268
+ fn derives_copy ( & self , lib : & Library ) -> bool {
269
+ if self . is_incomplete ( lib) {
270
+ return false ;
271
+ }
272
+
273
+ !self . is_ptr ( )
274
+ }
275
+ }
276
+
277
+ impl < ' a > DerivesCopy for & ' a [ Field ] {
278
+ fn derives_copy ( & self , lib : & Library ) -> bool {
279
+ if self . is_incomplete ( lib) {
280
+ return false ;
281
+ }
282
+
283
+ for field in self . iter ( ) {
284
+ if field. is_ptr ( ) {
285
+ return false ;
286
+ }
287
+ }
288
+
289
+ true
290
+ }
291
+ }
292
+
293
+ impl DerivesCopy for Class {
294
+ fn derives_copy ( & self , lib : & Library ) -> bool {
295
+ if self . is_incomplete ( lib) {
296
+ return false ;
297
+ }
298
+
299
+ self . fields . as_slice ( ) . derives_copy ( lib)
300
+ }
301
+ }
302
+
303
+ impl DerivesCopy for Record {
304
+ #[ allow( clippy:: if_same_then_else) ]
305
+ fn derives_copy ( & self , lib : & Library ) -> bool {
306
+ if self . is_incomplete ( lib) {
307
+ return false ;
308
+ }
309
+
310
+ self . fields . as_slice ( ) . derives_copy ( lib)
311
+ }
312
+ }
313
+
314
+ impl DerivesCopy for Union {
315
+ fn derives_copy ( & self , lib : & Library ) -> bool {
316
+ if self . is_incomplete ( lib) {
317
+ return false ;
318
+ }
319
+
320
+ self . fields . as_slice ( ) . derives_copy ( lib)
321
+ }
322
+ }
323
+
324
+ impl DerivesCopy for Function {
325
+ fn derives_copy ( & self , lib : & Library ) -> bool {
326
+ if self . is_incomplete ( lib) {
327
+ return false ;
328
+ }
329
+
330
+ true
331
+ }
332
+ }
333
+
334
+ impl DerivesCopy for TypeId {
335
+ fn derives_copy ( & self , lib : & Library ) -> bool {
336
+ if self . is_incomplete ( lib) {
337
+ return false ;
338
+ }
339
+
340
+ lib. type_ ( * self ) . derives_copy ( lib)
341
+ }
342
+ }
343
+
344
+ impl DerivesCopy for Type {
345
+ fn derives_copy ( & self , lib : & Library ) -> bool {
346
+ if self . is_incomplete ( lib) {
347
+ return false ;
348
+ }
349
+
350
+ match * self {
351
+ Type :: Fundamental ( ref fundamental) => fundamental. derives_copy ( lib) ,
352
+ Type :: Alias ( ref alias) => alias. derives_copy ( lib) ,
353
+ Type :: FixedArray ( tid, ..) => tid. derives_copy ( lib) ,
354
+ Type :: Class ( ref klass) => klass. derives_copy ( lib) ,
355
+ Type :: Record ( ref record) => record. derives_copy ( lib) ,
356
+ Type :: Union ( ref union) => union. derives_copy ( lib) ,
357
+ Type :: Function ( ref function) => function. derives_copy ( lib) ,
358
+ Type :: Enumeration ( ..) | Type :: Bitfield ( ..) | Type :: Interface ( ..) => true ,
359
+ Type :: Custom ( ..)
360
+ | Type :: Array ( ..)
361
+ | Type :: CArray ( ..)
362
+ | Type :: PtrArray ( ..)
363
+ | Type :: HashTable ( ..)
364
+ | Type :: List ( ..)
365
+ | Type :: SList ( ..) => false ,
366
+ }
240
367
}
241
368
}
242
369
0 commit comments