zerocopy-derive 0.8.49-alpha

Custom derive for traits from the zerocopy crate
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
// Copyright 2019 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

#[macro_use]
extern crate zerocopy_renamed;

fn main() {}

//
// Generic errors
//

#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr("foo")]
//~[msrv, stable, nightly]^ ERROR: unrecognized representation hint
//~[msrv, stable, nightly]^^ ERROR: meta item in `repr` must be an identifier
enum Generic1 {
    A,
}

#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(foo)]
//~[msrv, stable, nightly]^ ERROR: unrecognized representation hint
//~[msrv, stable, nightly]^^ ERROR: unrecognized representation hint
enum Generic2 {
    A,
}

#[derive(FromBytes)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(transparent)]
enum Generic3 {
    A,
}

#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8, u16)]
//~[msrv, stable, nightly]^ ERROR: this conflicts with another representation hint
//~[msrv, stable, nightly]^^ ERROR: conflicting representation hints
enum Generic4 {
    A,
}

#[derive(FromBytes)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
#[zerocopy(crate = "zerocopy_renamed")]
enum Generic5 {
    A,
}

//
// Immutable errors
//

#[derive(Immutable)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `UnsafeCell<()>: Immutable` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
enum Immutable1 {
    A(core::cell::UnsafeCell<()>),
}

#[derive(Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
enum Never {}

#[derive(Immutable)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `UnsafeCell<u8>: Immutable` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
enum Immutable2 {
    Uninhabited(Never, core::cell::UnsafeCell<u8>),
    Inhabited(u8),
}

//
// TryFromBytes errors
//

#[derive(TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
enum TryFromBytes1 {
    A,
}

#[derive(TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
enum TryFromBytes2 {
    A,
    B(u8),
}

struct NotTryFromBytes;

#[derive(TryFromBytes)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `NotTryFromBytes: TryFromBytes` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum TryFromBytes3 {
    A(NotTryFromBytes),
}

//
// FromZeros errors
//

#[derive(FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
enum FromZeros1 {
    A(u8),
}

#[derive(FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
enum FromZeros2 {
    A,
    B(u8),
}

#[derive(FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
enum FromZeros3 {
    A = 1,
    B,
}

#[derive(FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
//~[msrv, stable, nightly]^ ERROR: FromZeros only supported on enums with a variant that has a discriminant of `0`
#[repr(u8)]
enum FromZeros4 {
    A = 1,
    B = 2,
}

const NEGATIVE_ONE: i8 = -1;

#[derive(FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
//~[msrv, stable, nightly]^ ERROR: FromZeros only supported on enums with a variant that has a discriminant of `0`
#[repr(i8)]
enum FromZeros5 {
    A = NEGATIVE_ONE,
    B,
}

struct NotFromZeros;

#[derive(FromZeros)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `NotFromZeros: TryFromBytes` is not satisfied
//~[msrv, stable, nightly]^^ ERROR: the trait bound `NotFromZeros: FromZeros` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum FromZeros6 {
    A(NotFromZeros),
}

#[derive(FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
//~[msrv, stable, nightly]^ ERROR: FromZeros only supported on enums with a variant that has a discriminant of `0`
#[repr(u8)]
enum FromZeros7 {
    A = 1,
    //~[msrv]^ ERROR: custom discriminant values are not allowed in enums with tuple or struct variants
    B(NotFromZeros),
}

//
// FromBytes errors
//

#[derive(FromBytes)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
#[zerocopy(crate = "zerocopy_renamed")]
enum FromBytes1 {
    A,
}

#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
//~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
enum FromBytes2 {
    A,
}

#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(usize)]
//~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
enum FromBytes3 {
    A,
}

#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(isize)]
//~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
enum FromBytes4 {
    A,
}

#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u32)]
//~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
enum FromBytes5 {
    A,
}

#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i32)]
//~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
enum FromBytes6 {
    A,
}

#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u64)]
//~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
enum FromBytes7 {
    A,
}

#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i64)]
//~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
enum FromBytes8 {
    A,
}

#[derive(FromBytes)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `bool: FromBytes` is not satisfied
//~[stable, nightly]^^ ERROR: the trait bound `bool: FromBytes` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum FooU8 {
    Variant0,
    Variant1,
    Variant2,
    Variant3,
    Variant4,
    Variant5,
    Variant6,
    Variant7,
    Variant8,
    Variant9,
    Variant10,
    Variant11,
    Variant12,
    Variant13,
    Variant14,
    Variant15,
    Variant16,
    Variant17,
    Variant18,
    Variant19,
    Variant20,
    Variant21,
    Variant22,
    Variant23,
    Variant24,
    Variant25,
    Variant26,
    Variant27,
    Variant28,
    Variant29,
    Variant30,
    Variant31,
    Variant32,
    Variant33,
    Variant34,
    Variant35,
    Variant36,
    Variant37,
    Variant38,
    Variant39,
    Variant40,
    Variant41,
    Variant42,
    Variant43,
    Variant44,
    Variant45,
    Variant46,
    Variant47,
    Variant48,
    Variant49,
    Variant50,
    Variant51,
    Variant52,
    Variant53,
    Variant54,
    Variant55,
    Variant56,
    Variant57,
    Variant58,
    Variant59,
    Variant60,
    Variant61,
    Variant62,
    Variant63,
    Variant64,
    Variant65,
    Variant66,
    Variant67,
    Variant68,
    Variant69,
    Variant70,
    Variant71,
    Variant72,
    Variant73,
    Variant74,
    Variant75,
    Variant76,
    Variant77,
    Variant78,
    Variant79,
    Variant80,
    Variant81,
    Variant82,
    Variant83,
    Variant84,
    Variant85,
    Variant86,
    Variant87,
    Variant88,
    Variant89,
    Variant90,
    Variant91,
    Variant92,
    Variant93,
    Variant94,
    Variant95,
    Variant96,
    Variant97,
    Variant98,
    Variant99,
    Variant100,
    Variant101,
    Variant102,
    Variant103,
    Variant104,
    Variant105,
    Variant106,
    Variant107,
    Variant108,
    Variant109,
    Variant110,
    Variant111,
    Variant112,
    Variant113,
    Variant114,
    Variant115,
    Variant116,
    Variant117,
    Variant118,
    Variant119,
    Variant120,
    Variant121,
    Variant122,
    Variant123,
    Variant124,
    Variant125,
    Variant126,
    Variant127,
    Variant128,
    Variant129,
    Variant130,
    Variant131,
    Variant132,
    Variant133,
    Variant134,
    Variant135,
    Variant136,
    Variant137,
    Variant138,
    Variant139,
    Variant140,
    Variant141,
    Variant142,
    Variant143,
    Variant144,
    Variant145,
    Variant146,
    Variant147,
    Variant148,
    Variant149,
    Variant150,
    Variant151,
    Variant152,
    Variant153,
    Variant154,
    Variant155,
    Variant156,
    Variant157,
    Variant158,
    Variant159,
    Variant160,
    Variant161,
    Variant162,
    Variant163,
    Variant164,
    Variant165,
    Variant166,
    Variant167,
    Variant168,
    Variant169,
    Variant170,
    Variant171,
    Variant172,
    Variant173,
    Variant174,
    Variant175,
    Variant176,
    Variant177,
    Variant178,
    Variant179,
    Variant180,
    Variant181,
    Variant182,
    Variant183,
    Variant184,
    Variant185,
    Variant186,
    Variant187,
    Variant188,
    Variant189,
    Variant190,
    Variant191,
    Variant192,
    Variant193,
    Variant194,
    Variant195,
    Variant196,
    Variant197,
    Variant198,
    Variant199,
    Variant200,
    Variant201,
    Variant202,
    Variant203,
    Variant204,
    Variant205,
    Variant206,
    Variant207,
    Variant208,
    Variant209,
    Variant210,
    Variant211,
    Variant212,
    Variant213,
    Variant214,
    Variant215,
    Variant216,
    Variant217,
    Variant218,
    Variant219,
    Variant220,
    Variant221,
    Variant222,
    Variant223,
    Variant224,
    Variant225,
    Variant226,
    Variant227,
    Variant228,
    Variant229,
    Variant230,
    Variant231,
    Variant232,
    Variant233,
    Variant234,
    Variant235,
    Variant236,
    Variant237,
    Variant238,
    Variant239,
    Variant240,
    Variant241,
    Variant242,
    Variant243,
    Variant244,
    Variant245,
    Variant246,
    Variant247,
    Variant248,
    Variant249,
    Variant250,
    Variant251,
    Variant252,
    Variant253,
    Variant254,
    Variant255(bool),
}

//
// Unaligned errors
//

#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
enum Unaligned1 {
    A,
}

#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u16)]
enum Unaligned2 {
    A,
}

#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i16)]
enum Unaligned3 {
    A,
}

#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u32)]
enum Unaligned4 {
    A,
}

#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i32)]
enum Unaligned5 {
    A,
}

#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u64)]
enum Unaligned6 {
    A,
}

#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i64)]
enum Unaligned7 {
    A,
}

#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(usize)]
enum Unaligned8 {
    A,
}

#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(isize)]
enum Unaligned9 {
    A,
}

#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8, align(2))]
//~[msrv, stable, nightly]^ ERROR: cannot derive `Unaligned` on type with alignment greater than 1
enum Unaligned10 {
    A,
}

#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i8, align(2))]
//~[msrv, stable, nightly]^ ERROR: cannot derive `Unaligned` on type with alignment greater than 1
enum Unaligned11 {
    A,
}

#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(align(1), align(2))]
//~[msrv, stable, nightly]^ ERROR: this conflicts with another representation hint
enum Unaligned12 {
    A,
}

#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(align(2), align(4))]
//~[msrv, stable, nightly]^ ERROR: this conflicts with another representation hint
enum Unaligned13 {
    A,
}

//
// IntoBytes errors
//

#[derive(IntoBytes)]
//~[msrv]^ ERROR: the trait bound `(): PaddingFree<IntoBytes1, 1_usize>` is not satisfied
//~[stable, nightly]^^ ERROR: `IntoBytes1` has 1 total byte(s) of padding
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum IntoBytes1 {
    A,
    B(u8),
}

#[derive(IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, align(4))]
struct Align4IntoBytes(u32);

#[derive(IntoBytes)]
//~[msrv]^ ERROR: the trait bound `(): PaddingFree<IntoBytes2, 3_usize>` is not satisfied
//~[stable, nightly]^^ ERROR: `IntoBytes2` has 3 total byte(s) of padding
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum IntoBytes2 {
    A(Align4IntoBytes),
}

#[derive(IntoBytes)]
//~[msrv]^ ERROR: the trait bound `(): PaddingFree<IntoBytes3, 2_usize>` is not satisfied
//~[stable, nightly]^^ ERROR: `IntoBytes3` has 2 total byte(s) of padding
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u32)]
enum IntoBytes3 {
    A(u32),
    B(u16),
}

#[derive(IntoBytes)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
#[zerocopy(crate = "zerocopy_renamed")]
enum IntoBytes4 {
    A(u32),
    B(u16),
}

#[derive(IntoBytes)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
#[zerocopy(crate = "zerocopy_renamed")]
enum IntoBytes5 {
    A(u32),
}

#[derive(IntoBytes)]
//~[msrv, stable, nightly]^ ERROR: generic `Self` types are currently not permitted in anonymous constants
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum IntoBytes6<T> {
    A(T),
    //~[msrv, stable, nightly]^ ERROR: generic parameters may not be used in const operations
}

#[derive(IntoBytes)]
//~[msrv]^ ERROR: the trait bound `(): PaddingFree<IntoBytes7, 1_usize>` is not satisfied
//~[stable, nightly]^^ ERROR: `IntoBytes7` has 1 total byte(s) of padding
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8, align(2))]
enum IntoBytes7 {
    A,
}