Debian Codegraph @

debian/rust-vendor/zerocopy-derive/tests/ui/enum.rs

raw
1 // Copyright 2019 The Fuchsia Authors
2 //
3 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
4 // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
5 // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
6 // This file may not be copied, modified, or distributed except according to
7 // those terms.
8
9 #[macro_use]
10 extern crate zerocopy_renamed;
11
12 fn main() {}
13
14 //
15 // Generic errors
16 //
17
18 #[derive(FromBytes)]
19 #[zerocopy(crate = "zerocopy_renamed")]
20 #[repr("foo")]
21 //~[msrv, stable, nightly]^ ERROR: unrecognized representation hint
22 //~[msrv, stable, nightly]^^ ERROR: meta item in `repr` must be an identifier
23 enum Generic1 {
24 A,
25 }
26
27 #[derive(FromBytes)]
28 #[zerocopy(crate = "zerocopy_renamed")]
29 #[repr(foo)]
30 //~[msrv, stable, nightly]^ ERROR: unrecognized representation hint
31 //~[msrv, stable, nightly]^^ ERROR: unrecognized representation hint
32 enum Generic2 {
33 A,
34 }
35
36 #[derive(FromBytes)]
37 //~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
38 #[zerocopy(crate = "zerocopy_renamed")]
39 #[repr(transparent)]
40 enum Generic3 {
41 A,
42 }
43
44 #[derive(FromBytes)]
45 #[zerocopy(crate = "zerocopy_renamed")]
46 #[repr(u8, u16)]
47 //~[msrv, stable, nightly]^ ERROR: this conflicts with another representation hint
48 //~[msrv, stable, nightly]^^ ERROR: conflicting representation hints
49 enum Generic4 {
50 A,
51 }
52
53 #[derive(FromBytes)]
54 //~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
55 #[zerocopy(crate = "zerocopy_renamed")]
56 enum Generic5 {
57 A,
58 }
59
60 //
61 // Immutable errors
62 //
63
64 #[derive(Immutable)]
65 //~[msrv, stable, nightly]^ ERROR: the trait bound `UnsafeCell<()>: Immutable` is not satisfied
66 #[zerocopy(crate = "zerocopy_renamed")]
67 enum Immutable1 {
68 A(core::cell::UnsafeCell<()>),
69 }
70
71 #[derive(Immutable)]
72 #[zerocopy(crate = "zerocopy_renamed")]
73 enum Never {}
74
75 #[derive(Immutable)]
76 //~[msrv, stable, nightly]^ ERROR: the trait bound `UnsafeCell<u8>: Immutable` is not satisfied
77 #[zerocopy(crate = "zerocopy_renamed")]
78 enum Immutable2 {
79 Uninhabited(Never, core::cell::UnsafeCell<u8>),
80 Inhabited(u8),
81 }
82
83 //
84 // TryFromBytes errors
85 //
86
87 #[derive(TryFromBytes)]
88 #[zerocopy(crate = "zerocopy_renamed")]
89 //~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
90 enum TryFromBytes1 {
91 A,
92 }
93
94 #[derive(TryFromBytes)]
95 #[zerocopy(crate = "zerocopy_renamed")]
96 //~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
97 enum TryFromBytes2 {
98 A,
99 B(u8),
100 }
101
102 struct NotTryFromBytes;
103
104 #[derive(TryFromBytes)]
105 //~[msrv, stable, nightly]^ ERROR: the trait bound `NotTryFromBytes: TryFromBytes` is not satisfied
106 #[zerocopy(crate = "zerocopy_renamed")]
107 #[repr(u8)]
108 enum TryFromBytes3 {
109 A(NotTryFromBytes),
110 }
111
112 //
113 // FromZeros errors
114 //
115
116 #[derive(FromZeros)]
117 #[zerocopy(crate = "zerocopy_renamed")]
118 //~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
119 enum FromZeros1 {
120 A(u8),
121 }
122
123 #[derive(FromZeros)]
124 #[zerocopy(crate = "zerocopy_renamed")]
125 //~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
126 enum FromZeros2 {
127 A,
128 B(u8),
129 }
130
131 #[derive(FromZeros)]
132 #[zerocopy(crate = "zerocopy_renamed")]
133 //~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
134 enum FromZeros3 {
135 A = 1,
136 B,
137 }
138
139 #[derive(FromZeros)]
140 #[zerocopy(crate = "zerocopy_renamed")]
141 //~[msrv, stable, nightly]^ ERROR: FromZeros only supported on enums with a variant that has a discriminant of `0`
142 #[repr(u8)]
143 enum FromZeros4 {
144 A = 1,
145 B = 2,
146 }
147
148 const NEGATIVE_ONE: i8 = -1;
149
150 #[derive(FromZeros)]
151 #[zerocopy(crate = "zerocopy_renamed")]
152 //~[msrv, stable, nightly]^ ERROR: FromZeros only supported on enums with a variant that has a discriminant of `0`
153 #[repr(i8)]
154 enum FromZeros5 {
155 A = NEGATIVE_ONE,
156 B,
157 }
158
159 struct NotFromZeros;
160
161 #[derive(FromZeros)]
162 //~[msrv, stable, nightly]^ ERROR: the trait bound `NotFromZeros: TryFromBytes` is not satisfied
163 //~[msrv, stable, nightly]^^ ERROR: the trait bound `NotFromZeros: FromZeros` is not satisfied
164 #[zerocopy(crate = "zerocopy_renamed")]
165 #[repr(u8)]
166 enum FromZeros6 {
167 A(NotFromZeros),
168 }
169
170 #[derive(FromZeros)]
171 #[zerocopy(crate = "zerocopy_renamed")]
172 //~[msrv, stable, nightly]^ ERROR: FromZeros only supported on enums with a variant that has a discriminant of `0`
173 #[repr(u8)]
174 enum FromZeros7 {
175 A = 1,
176 //~[msrv]^ ERROR: custom discriminant values are not allowed in enums with tuple or struct variants
177 B(NotFromZeros),
178 }
179
180 //
181 // FromBytes errors
182 //
183
184 #[derive(FromBytes)]
185 //~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
186 #[zerocopy(crate = "zerocopy_renamed")]
187 enum FromBytes1 {
188 A,
189 }
190
191 #[derive(FromBytes)]
192 #[zerocopy(crate = "zerocopy_renamed")]
193 #[repr(C)]
194 //~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
195 enum FromBytes2 {
196 A,
197 }
198
199 #[derive(FromBytes)]
200 #[zerocopy(crate = "zerocopy_renamed")]
201 #[repr(usize)]
202 //~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
203 enum FromBytes3 {
204 A,
205 }
206
207 #[derive(FromBytes)]
208 #[zerocopy(crate = "zerocopy_renamed")]
209 #[repr(isize)]
210 //~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
211 enum FromBytes4 {
212 A,
213 }
214
215 #[derive(FromBytes)]
216 #[zerocopy(crate = "zerocopy_renamed")]
217 #[repr(u32)]
218 //~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
219 enum FromBytes5 {
220 A,
221 }
222
223 #[derive(FromBytes)]
224 #[zerocopy(crate = "zerocopy_renamed")]
225 #[repr(i32)]
226 //~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
227 enum FromBytes6 {
228 A,
229 }
230
231 #[derive(FromBytes)]
232 #[zerocopy(crate = "zerocopy_renamed")]
233 #[repr(u64)]
234 //~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
235 enum FromBytes7 {
236 A,
237 }
238
239 #[derive(FromBytes)]
240 #[zerocopy(crate = "zerocopy_renamed")]
241 #[repr(i64)]
242 //~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
243 enum FromBytes8 {
244 A,
245 }
246
247 #[derive(FromBytes)]
248 //~[msrv, stable, nightly]^ ERROR: the trait bound `bool: FromBytes` is not satisfied
249 //~[stable, nightly]^^ ERROR: the trait bound `bool: FromBytes` is not satisfied
250 #[zerocopy(crate = "zerocopy_renamed")]
251 #[repr(u8)]
252 enum FooU8 {
253 Variant0,
254 Variant1,
255 Variant2,
256 Variant3,
257 Variant4,
258 Variant5,
259 Variant6,
260 Variant7,
261 Variant8,
262 Variant9,
263 Variant10,
264 Variant11,
265 Variant12,
266 Variant13,
267 Variant14,
268 Variant15,
269 Variant16,
270 Variant17,
271 Variant18,
272 Variant19,
273 Variant20,
274 Variant21,
275 Variant22,
276 Variant23,
277 Variant24,
278 Variant25,
279 Variant26,
280 Variant27,
281 Variant28,
282 Variant29,
283 Variant30,
284 Variant31,
285 Variant32,
286 Variant33,
287 Variant34,
288 Variant35,
289 Variant36,
290 Variant37,
291 Variant38,
292 Variant39,
293 Variant40,
294 Variant41,
295 Variant42,
296 Variant43,
297 Variant44,
298 Variant45,
299 Variant46,
300 Variant47,
301 Variant48,
302 Variant49,
303 Variant50,
304 Variant51,
305 Variant52,
306 Variant53,
307 Variant54,
308 Variant55,
309 Variant56,
310 Variant57,
311 Variant58,
312 Variant59,
313 Variant60,
314 Variant61,
315 Variant62,
316 Variant63,
317 Variant64,
318 Variant65,
319 Variant66,
320 Variant67,
321 Variant68,
322 Variant69,
323 Variant70,
324 Variant71,
325 Variant72,
326 Variant73,
327 Variant74,
328 Variant75,
329 Variant76,
330 Variant77,
331 Variant78,
332 Variant79,
333 Variant80,
334 Variant81,
335 Variant82,
336 Variant83,
337 Variant84,
338 Variant85,
339 Variant86,
340 Variant87,
341 Variant88,
342 Variant89,
343 Variant90,
344 Variant91,
345 Variant92,
346 Variant93,
347 Variant94,
348 Variant95,
349 Variant96,
350 Variant97,
351 Variant98,
352 Variant99,
353 Variant100,
354 Variant101,
355 Variant102,
356 Variant103,
357 Variant104,
358 Variant105,
359 Variant106,
360 Variant107,
361 Variant108,
362 Variant109,
363 Variant110,
364 Variant111,
365 Variant112,
366 Variant113,
367 Variant114,
368 Variant115,
369 Variant116,
370 Variant117,
371 Variant118,
372 Variant119,
373 Variant120,
374 Variant121,
375 Variant122,
376 Variant123,
377 Variant124,
378 Variant125,
379 Variant126,
380 Variant127,
381 Variant128,
382 Variant129,
383 Variant130,
384 Variant131,
385 Variant132,
386 Variant133,
387 Variant134,
388 Variant135,
389 Variant136,
390 Variant137,
391 Variant138,
392 Variant139,
393 Variant140,
394 Variant141,
395 Variant142,
396 Variant143,
397 Variant144,
398 Variant145,
399 Variant146,
400 Variant147,
401 Variant148,
402 Variant149,
403 Variant150,
404 Variant151,
405 Variant152,
406 Variant153,
407 Variant154,
408 Variant155,
409 Variant156,
410 Variant157,
411 Variant158,
412 Variant159,
413 Variant160,
414 Variant161,
415 Variant162,
416 Variant163,
417 Variant164,
418 Variant165,
419 Variant166,
420 Variant167,
421 Variant168,
422 Variant169,
423 Variant170,
424 Variant171,
425 Variant172,
426 Variant173,
427 Variant174,
428 Variant175,
429 Variant176,
430 Variant177,
431 Variant178,
432 Variant179,
433 Variant180,
434 Variant181,
435 Variant182,
436 Variant183,
437 Variant184,
438 Variant185,
439 Variant186,
440 Variant187,
441 Variant188,
442 Variant189,
443 Variant190,
444 Variant191,
445 Variant192,
446 Variant193,
447 Variant194,
448 Variant195,
449 Variant196,
450 Variant197,
451 Variant198,
452 Variant199,
453 Variant200,
454 Variant201,
455 Variant202,
456 Variant203,
457 Variant204,
458 Variant205,
459 Variant206,
460 Variant207,
461 Variant208,
462 Variant209,
463 Variant210,
464 Variant211,
465 Variant212,
466 Variant213,
467 Variant214,
468 Variant215,
469 Variant216,
470 Variant217,
471 Variant218,
472 Variant219,
473 Variant220,
474 Variant221,
475 Variant222,
476 Variant223,
477 Variant224,
478 Variant225,
479 Variant226,
480 Variant227,
481 Variant228,
482 Variant229,
483 Variant230,
484 Variant231,
485 Variant232,
486 Variant233,
487 Variant234,
488 Variant235,
489 Variant236,
490 Variant237,
491 Variant238,
492 Variant239,
493 Variant240,
494 Variant241,
495 Variant242,
496 Variant243,
497 Variant244,
498 Variant245,
499 Variant246,
500 Variant247,
501 Variant248,
502 Variant249,
503 Variant250,
504 Variant251,
505 Variant252,
506 Variant253,
507 Variant254,
508 Variant255(bool),
509 }
510
511 //
512 // Unaligned errors
513 //
514
515 #[derive(Unaligned)]
516 //~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
517 #[zerocopy(crate = "zerocopy_renamed")]
518 #[repr(C)]
519 enum Unaligned1 {
520 A,
521 }
522
523 #[derive(Unaligned)]
524 //~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
525 #[zerocopy(crate = "zerocopy_renamed")]
526 #[repr(u16)]
527 enum Unaligned2 {
528 A,
529 }
530
531 #[derive(Unaligned)]
532 //~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
533 #[zerocopy(crate = "zerocopy_renamed")]
534 #[repr(i16)]
535 enum Unaligned3 {
536 A,
537 }
538
539 #[derive(Unaligned)]
540 //~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
541 #[zerocopy(crate = "zerocopy_renamed")]
542 #[repr(u32)]
543 enum Unaligned4 {
544 A,
545 }
546
547 #[derive(Unaligned)]
548 //~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
549 #[zerocopy(crate = "zerocopy_renamed")]
550 #[repr(i32)]
551 enum Unaligned5 {
552 A,
553 }
554
555 #[derive(Unaligned)]
556 //~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
557 #[zerocopy(crate = "zerocopy_renamed")]
558 #[repr(u64)]
559 enum Unaligned6 {
560 A,
561 }
562
563 #[derive(Unaligned)]
564 //~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
565 #[zerocopy(crate = "zerocopy_renamed")]
566 #[repr(i64)]
567 enum Unaligned7 {
568 A,
569 }
570
571 #[derive(Unaligned)]
572 //~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
573 #[zerocopy(crate = "zerocopy_renamed")]
574 #[repr(usize)]
575 enum Unaligned8 {
576 A,
577 }
578
579 #[derive(Unaligned)]
580 //~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
581 #[zerocopy(crate = "zerocopy_renamed")]
582 #[repr(isize)]
583 enum Unaligned9 {
584 A,
585 }
586
587 #[derive(Unaligned)]
588 #[zerocopy(crate = "zerocopy_renamed")]
589 #[repr(u8, align(2))]
590 //~[msrv, stable, nightly]^ ERROR: cannot derive `Unaligned` on type with alignment greater than 1
591 enum Unaligned10 {
592 A,
593 }
594
595 #[derive(Unaligned)]
596 #[zerocopy(crate = "zerocopy_renamed")]
597 #[repr(i8, align(2))]
598 //~[msrv, stable, nightly]^ ERROR: cannot derive `Unaligned` on type with alignment greater than 1
599 enum Unaligned11 {
600 A,
601 }
602
603 #[derive(Unaligned)]
604 #[zerocopy(crate = "zerocopy_renamed")]
605 #[repr(align(1), align(2))]
606 //~[msrv, stable, nightly]^ ERROR: this conflicts with another representation hint
607 enum Unaligned12 {
608 A,
609 }
610
611 #[derive(Unaligned)]
612 #[zerocopy(crate = "zerocopy_renamed")]
613 #[repr(align(2), align(4))]
614 //~[msrv, stable, nightly]^ ERROR: this conflicts with another representation hint
615 enum Unaligned13 {
616 A,
617 }
618
619 //
620 // IntoBytes errors
621 //
622
623 #[derive(IntoBytes)]
624 //~[msrv]^ ERROR: the trait bound `(): PaddingFree<IntoBytes1, 1_usize>` is not satisfied
625 //~[stable, nightly]^^ ERROR: `IntoBytes1` has 1 total byte(s) of padding
626 #[zerocopy(crate = "zerocopy_renamed")]
627 #[repr(u8)]
628 enum IntoBytes1 {
629 A,
630 B(u8),
631 }
632
633 #[derive(IntoBytes)]
634 #[zerocopy(crate = "zerocopy_renamed")]
635 #[repr(C, align(4))]
636 struct Align4IntoBytes(u32);
637
638 #[derive(IntoBytes)]
639 //~[msrv]^ ERROR: the trait bound `(): PaddingFree<IntoBytes2, 3_usize>` is not satisfied
640 //~[stable, nightly]^^ ERROR: `IntoBytes2` has 3 total byte(s) of padding
641 #[zerocopy(crate = "zerocopy_renamed")]
642 #[repr(u8)]
643 enum IntoBytes2 {
644 A(Align4IntoBytes),
645 }
646
647 #[derive(IntoBytes)]
648 //~[msrv]^ ERROR: the trait bound `(): PaddingFree<IntoBytes3, 2_usize>` is not satisfied
649 //~[stable, nightly]^^ ERROR: `IntoBytes3` has 2 total byte(s) of padding
650 #[zerocopy(crate = "zerocopy_renamed")]
651 #[repr(u32)]
652 enum IntoBytes3 {
653 A(u32),
654 B(u16),
655 }
656
657 #[derive(IntoBytes)]
658 //~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
659 #[zerocopy(crate = "zerocopy_renamed")]
660 enum IntoBytes4 {
661 A(u32),
662 B(u16),
663 }
664
665 #[derive(IntoBytes)]
666 //~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
667 #[zerocopy(crate = "zerocopy_renamed")]
668 enum IntoBytes5 {
669 A(u32),
670 }
671
672 #[derive(IntoBytes)]
673 //~[msrv, stable, nightly]^ ERROR: generic `Self` types are currently not permitted in anonymous constants
674 #[zerocopy(crate = "zerocopy_renamed")]
675 #[repr(u8)]
676 enum IntoBytes6<T> {
677 A(T),
678 //~[msrv, stable, nightly]^ ERROR: generic parameters may not be used in const operations
679 }
680
681 #[derive(IntoBytes)]
682 //~[msrv]^ ERROR: the trait bound `(): PaddingFree<IntoBytes7, 1_usize>` is not satisfied
683 //~[stable, nightly]^^ ERROR: `IntoBytes7` has 1 total byte(s) of padding
684 #[zerocopy(crate = "zerocopy_renamed")]
685 #[repr(u8, align(2))]
686 enum IntoBytes7 {
687 A,
688 }