|
1 | | -//@ revisions: old future |
2 | 1 | //@ run-pass |
3 | | -//@ [old] edition:2024 |
4 | | -//@ [future] edition:future |
5 | | -//@ [future] compile-flags: -Z unstable-options |
6 | 2 |
|
7 | 3 | #![allow(dead_code)] |
8 | | -#![cfg_attr(future, feature(offset_of_enum))] |
| 4 | +#![feature(offset_of_enum)] |
9 | 5 |
|
10 | | -#[cfg(future)] |
11 | 6 | use std::mem::{align_of, offset_of}; |
12 | 7 | use std::mem::size_of; |
13 | 8 | use std::num::NonZero; |
@@ -77,64 +72,55 @@ enum ChooseFittingNiche { |
77 | 72 | fn main() { |
78 | 73 | assert_eq!(size_of::<Inner>(), 8); |
79 | 74 |
|
80 | | - #[cfg(old)] |
81 | | - { |
82 | | - assert_eq!(size_of::<Outer>(), 12); |
83 | | - assert_eq!(size_of::<RepackPadding>(), 12); |
84 | | - } |
85 | | - |
86 | | - #[cfg(future)] |
87 | | - { |
88 | | - assert_eq!(size_of::<Outer>(), 8); |
89 | | - assert_eq!(size_of::<RepackPadding>(), 8); |
90 | | - |
91 | | - assert_eq!(size_of::<RepackedBase>(), 8); |
92 | | - assert_eq!(align_of::<RepackedBase>(), 4); |
93 | | - assert_eq!(offset_of!(RepackedBase, int32), 0); |
94 | | - assert_eq!(offset_of!(RepackedBase, boolean), 4); |
95 | | - |
96 | | - assert_eq!(size_of::<RepackedAroundNiche>(), 8); |
97 | | - assert_eq!(align_of::<RepackedAroundNiche>(), 4); |
98 | | - assert_eq!(size_of::<Option<RepackedAroundNiche>>(), 8); |
99 | | - assert_eq!(offset_of!(RepackedAroundNiche, A.0), 0); |
100 | | - assert_eq!(offset_of!(RepackedAroundNiche, B.1), 0); |
101 | | - assert_eq!(offset_of!(RepackedAroundNiche, B.2), 5); |
102 | | - assert_eq!(offset_of!(RepackedAroundNiche, B.0), 6); |
103 | | - |
104 | | - assert_eq!(size_of::<NestedRepackedAroundNiche>(), 8); |
105 | | - assert_eq!(align_of::<NestedRepackedAroundNiche>(), 4); |
106 | | - assert_eq!(size_of::<Option<NestedRepackedAroundNiche>>(), 8); |
107 | | - assert_eq!(offset_of!(NestedRepackedAroundNiche, A.0), 0); |
108 | | - assert_eq!(offset_of!(NestedRepackedAroundNiche, B.1), 0); |
109 | | - assert_eq!(offset_of!(NestedRepackedAroundNiche, B.2), 5); |
110 | | - assert_eq!(offset_of!(NestedRepackedAroundNiche, B.0), 6); |
111 | | - |
112 | | - assert_eq!(size_of::<RepackedPair>(), 4); |
113 | | - assert_eq!(align_of::<RepackedPair>(), 2); |
114 | | - assert_eq!(offset_of!(RepackedPair, field2), 0); |
115 | | - assert_eq!(offset_of!(RepackedPair, field3), 2); |
116 | | - |
117 | | - assert_eq!(size_of::<RepackedNestedAggregate>(), 8); |
118 | | - assert_eq!(align_of::<RepackedNestedAggregate>(), 4); |
119 | | - assert_eq!(size_of::<Option<RepackedNestedAggregate>>(), 8); |
120 | | - assert_eq!(offset_of!(RepackedNestedAggregate, B.0), 0); |
121 | | - assert_eq!(offset_of!(RepackedNestedAggregate, A.1), 0); |
122 | | - assert_eq!(offset_of!(RepackedNestedAggregate, A.0), 6); |
123 | | - |
124 | | - assert_eq!(size_of::<FittingNichePayload>(), 8); |
125 | | - assert_eq!(align_of::<FittingNichePayload>(), 4); |
126 | | - assert_eq!(offset_of!(FittingNichePayload, word), 0); |
127 | | - assert_eq!(offset_of!(FittingNichePayload, flag), 4); |
128 | | - |
129 | | - assert_eq!(size_of::<ChooseFittingNiche>(), 8); |
130 | | - assert_eq!(align_of::<ChooseFittingNiche>(), 4); |
131 | | - assert_eq!(size_of::<Option<ChooseFittingNiche>>(), 8); |
132 | | - assert_eq!(offset_of!(ChooseFittingNiche, WideNiche.0), 0); |
133 | | - assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheFront.1), 0); |
134 | | - assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheFront.2), 5); |
135 | | - assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheFront.0), 6); |
136 | | - assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheBack.1), 0); |
137 | | - assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheBack.2), 5); |
138 | | - assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheBack.0), 6); |
139 | | - } |
| 75 | + assert_eq!(size_of::<Outer>(), 8); |
| 76 | + assert_eq!(size_of::<RepackPadding>(), 8); |
| 77 | + |
| 78 | + assert_eq!(size_of::<RepackedBase>(), 8); |
| 79 | + assert_eq!(align_of::<RepackedBase>(), 4); |
| 80 | + assert_eq!(offset_of!(RepackedBase, int32), 0); |
| 81 | + assert_eq!(offset_of!(RepackedBase, boolean), 4); |
| 82 | + |
| 83 | + assert_eq!(size_of::<RepackedAroundNiche>(), 8); |
| 84 | + assert_eq!(align_of::<RepackedAroundNiche>(), 4); |
| 85 | + assert_eq!(size_of::<Option<RepackedAroundNiche>>(), 8); |
| 86 | + assert_eq!(offset_of!(RepackedAroundNiche, A.0), 0); |
| 87 | + assert_eq!(offset_of!(RepackedAroundNiche, B.1), 0); |
| 88 | + assert_eq!(offset_of!(RepackedAroundNiche, B.2), 5); |
| 89 | + assert_eq!(offset_of!(RepackedAroundNiche, B.0), 6); |
| 90 | + |
| 91 | + assert_eq!(size_of::<NestedRepackedAroundNiche>(), 8); |
| 92 | + assert_eq!(align_of::<NestedRepackedAroundNiche>(), 4); |
| 93 | + assert_eq!(size_of::<Option<NestedRepackedAroundNiche>>(), 8); |
| 94 | + assert_eq!(offset_of!(NestedRepackedAroundNiche, A.0), 0); |
| 95 | + assert_eq!(offset_of!(NestedRepackedAroundNiche, B.1), 0); |
| 96 | + assert_eq!(offset_of!(NestedRepackedAroundNiche, B.2), 5); |
| 97 | + assert_eq!(offset_of!(NestedRepackedAroundNiche, B.0), 6); |
| 98 | + |
| 99 | + assert_eq!(size_of::<RepackedPair>(), 4); |
| 100 | + assert_eq!(align_of::<RepackedPair>(), 2); |
| 101 | + assert_eq!(offset_of!(RepackedPair, field2), 0); |
| 102 | + assert_eq!(offset_of!(RepackedPair, field3), 2); |
| 103 | + |
| 104 | + assert_eq!(size_of::<RepackedNestedAggregate>(), 8); |
| 105 | + assert_eq!(align_of::<RepackedNestedAggregate>(), 4); |
| 106 | + assert_eq!(size_of::<Option<RepackedNestedAggregate>>(), 8); |
| 107 | + assert_eq!(offset_of!(RepackedNestedAggregate, B.0), 0); |
| 108 | + assert_eq!(offset_of!(RepackedNestedAggregate, A.1), 0); |
| 109 | + assert_eq!(offset_of!(RepackedNestedAggregate, A.0), 6); |
| 110 | + |
| 111 | + assert_eq!(size_of::<FittingNichePayload>(), 8); |
| 112 | + assert_eq!(align_of::<FittingNichePayload>(), 4); |
| 113 | + assert_eq!(offset_of!(FittingNichePayload, word), 0); |
| 114 | + assert_eq!(offset_of!(FittingNichePayload, flag), 4); |
| 115 | + |
| 116 | + assert_eq!(size_of::<ChooseFittingNiche>(), 8); |
| 117 | + assert_eq!(align_of::<ChooseFittingNiche>(), 4); |
| 118 | + assert_eq!(size_of::<Option<ChooseFittingNiche>>(), 8); |
| 119 | + assert_eq!(offset_of!(ChooseFittingNiche, WideNiche.0), 0); |
| 120 | + assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheFront.1), 0); |
| 121 | + assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheFront.2), 5); |
| 122 | + assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheFront.0), 6); |
| 123 | + assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheBack.1), 0); |
| 124 | + assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheBack.2), 5); |
| 125 | + assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheBack.0), 6); |
140 | 126 | } |
0 commit comments