Skip to content

Commit 9bc1313

Browse files
committed
Add dump_layout tests for options of bool and char
1 parent 9838411 commit 9bc1313

2 files changed

Lines changed: 247 additions & 1 deletion

File tree

tests/ui/layout/debug.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,9 @@ union EmptyUnion {} //~ ERROR: has an unknown layout
8888
// (this error is never emitted to users).
8989
#[rustc_dump_layout(debug)]
9090
type TooGeneric<T> = T; //~ ERROR: does not have a fixed layout
91+
92+
#[rustc_dump_layout(debug)]
93+
type OptBool = Option<bool>; //~ ERROR: layout_of
94+
95+
#[rustc_dump_layout(debug)]
96+
type OptChar = Option<char>; //~ ERROR: layout_of

tests/ui/layout/debug.stderr

Lines changed: 241 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,246 @@ error: the type `T` does not have a fixed layout
614614
LL | type TooGeneric<T> = T;
615615
| ^^^^^^^^^^^^^^^^^^
616616

617-
error: aborting due to 20 previous errors
617+
error: layout_of(Option<bool>) = Layout {
618+
size: Size(1 bytes),
619+
align: AbiAlign {
620+
abi: Align(1 bytes),
621+
},
622+
backend_repr: Scalar(
623+
Initialized {
624+
value: Int(
625+
I8,
626+
false,
627+
),
628+
valid_range: 0..=2,
629+
},
630+
),
631+
fields: Arbitrary {
632+
offsets: [
633+
Size(0 bytes),
634+
],
635+
in_memory_order: [
636+
0,
637+
],
638+
},
639+
largest_niche: Some(
640+
Niche {
641+
offset: Size(0 bytes),
642+
value: Int(
643+
I8,
644+
false,
645+
),
646+
valid_range: 0..=2,
647+
},
648+
),
649+
uninhabited: false,
650+
variants: Multiple {
651+
tag: Initialized {
652+
value: Int(
653+
I8,
654+
false,
655+
),
656+
valid_range: 0..=2,
657+
},
658+
tag_encoding: Niche {
659+
untagged_variant: 1,
660+
niche_variants: 0..=0,
661+
niche_start: 2,
662+
},
663+
tag_field: 0,
664+
variants: [
665+
Layout {
666+
size: Size(0 bytes),
667+
align: AbiAlign {
668+
abi: Align(1 bytes),
669+
},
670+
backend_repr: Memory {
671+
sized: true,
672+
},
673+
fields: Arbitrary {
674+
offsets: [],
675+
in_memory_order: [],
676+
},
677+
largest_niche: None,
678+
uninhabited: false,
679+
variants: Single {
680+
index: 0,
681+
},
682+
max_repr_align: None,
683+
unadjusted_abi_align: Align(1 bytes),
684+
randomization_seed: $SEED,
685+
},
686+
Layout {
687+
size: Size(1 bytes),
688+
align: AbiAlign {
689+
abi: Align(1 bytes),
690+
},
691+
backend_repr: Scalar(
692+
Initialized {
693+
value: Int(
694+
I8,
695+
false,
696+
),
697+
valid_range: 0..=1,
698+
},
699+
),
700+
fields: Arbitrary {
701+
offsets: [
702+
Size(0 bytes),
703+
],
704+
in_memory_order: [
705+
0,
706+
],
707+
},
708+
largest_niche: Some(
709+
Niche {
710+
offset: Size(0 bytes),
711+
value: Int(
712+
I8,
713+
false,
714+
),
715+
valid_range: 0..=1,
716+
},
717+
),
718+
uninhabited: false,
719+
variants: Single {
720+
index: 1,
721+
},
722+
max_repr_align: None,
723+
unadjusted_abi_align: Align(1 bytes),
724+
randomization_seed: $SEED,
725+
},
726+
],
727+
},
728+
max_repr_align: None,
729+
unadjusted_abi_align: Align(1 bytes),
730+
randomization_seed: $SEED,
731+
}
732+
--> $DIR/debug.rs:93:1
733+
|
734+
LL | type OptBool = Option<bool>;
735+
| ^^^^^^^^^^^^
736+
737+
error: layout_of(Option<char>) = Layout {
738+
size: Size(4 bytes),
739+
align: AbiAlign {
740+
abi: Align(4 bytes),
741+
},
742+
backend_repr: Scalar(
743+
Initialized {
744+
value: Int(
745+
I32,
746+
false,
747+
),
748+
valid_range: 0..=1114112,
749+
},
750+
),
751+
fields: Arbitrary {
752+
offsets: [
753+
Size(0 bytes),
754+
],
755+
in_memory_order: [
756+
0,
757+
],
758+
},
759+
largest_niche: Some(
760+
Niche {
761+
offset: Size(0 bytes),
762+
value: Int(
763+
I32,
764+
false,
765+
),
766+
valid_range: 0..=1114112,
767+
},
768+
),
769+
uninhabited: false,
770+
variants: Multiple {
771+
tag: Initialized {
772+
value: Int(
773+
I32,
774+
false,
775+
),
776+
valid_range: 0..=1114112,
777+
},
778+
tag_encoding: Niche {
779+
untagged_variant: 1,
780+
niche_variants: 0..=0,
781+
niche_start: 1114112,
782+
},
783+
tag_field: 0,
784+
variants: [
785+
Layout {
786+
size: Size(0 bytes),
787+
align: AbiAlign {
788+
abi: Align(1 bytes),
789+
},
790+
backend_repr: Memory {
791+
sized: true,
792+
},
793+
fields: Arbitrary {
794+
offsets: [],
795+
in_memory_order: [],
796+
},
797+
largest_niche: None,
798+
uninhabited: false,
799+
variants: Single {
800+
index: 0,
801+
},
802+
max_repr_align: None,
803+
unadjusted_abi_align: Align(1 bytes),
804+
randomization_seed: $SEED,
805+
},
806+
Layout {
807+
size: Size(4 bytes),
808+
align: AbiAlign {
809+
abi: Align(4 bytes),
810+
},
811+
backend_repr: Scalar(
812+
Initialized {
813+
value: Int(
814+
I32,
815+
false,
816+
),
817+
valid_range: 0..=1114111,
818+
},
819+
),
820+
fields: Arbitrary {
821+
offsets: [
822+
Size(0 bytes),
823+
],
824+
in_memory_order: [
825+
0,
826+
],
827+
},
828+
largest_niche: Some(
829+
Niche {
830+
offset: Size(0 bytes),
831+
value: Int(
832+
I32,
833+
false,
834+
),
835+
valid_range: 0..=1114111,
836+
},
837+
),
838+
uninhabited: false,
839+
variants: Single {
840+
index: 1,
841+
},
842+
max_repr_align: None,
843+
unadjusted_abi_align: Align(4 bytes),
844+
randomization_seed: $SEED,
845+
},
846+
],
847+
},
848+
max_repr_align: None,
849+
unadjusted_abi_align: Align(4 bytes),
850+
randomization_seed: $SEED,
851+
}
852+
--> $DIR/debug.rs:96:1
853+
|
854+
LL | type OptChar = Option<char>;
855+
| ^^^^^^^^^^^^
856+
857+
error: aborting due to 22 previous errors
618858

619859
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)