@@ -4,67 +4,14 @@ use std::ops::Deref;
44use rustc_data_structures:: intern:: Interned ;
55use rustc_macros:: HashStable_Generic ;
66
7+ use crate :: layout:: { FieldIdx , VariantIdx } ;
78use crate :: {
89 AbiAlign , Align , BackendRepr , FieldsShape , Float , HasDataLayout , LayoutData , Niche ,
910 PointeeInfo , Primitive , Size , Variants ,
1011} ;
1112
1213// Explicitly import `Float` to avoid ambiguity with `Primitive::Float`.
1314
14- rustc_index:: newtype_index! {
15- /// The *source-order* index of a field in a variant.
16- ///
17- /// This is how most code after type checking refers to fields, rather than
18- /// using names (as names have hygiene complications and more complex lookup).
19- ///
20- /// Particularly for `repr(Rust)` types, this may not be the same as *layout* order.
21- /// (It is for `repr(C)` `struct`s, however.)
22- ///
23- /// For example, in the following types,
24- /// ```rust
25- /// # enum Never {}
26- /// # #[repr(u16)]
27- /// enum Demo1 {
28- /// Variant0 { a: Never, b: i32 } = 100,
29- /// Variant1 { c: u8, d: u64 } = 10,
30- /// }
31- /// struct Demo2 { e: u8, f: u16, g: u8 }
32- /// ```
33- /// `b` is `FieldIdx(1)` in `VariantIdx(0)`,
34- /// `d` is `FieldIdx(1)` in `VariantIdx(1)`, and
35- /// `f` is `FieldIdx(1)` in `VariantIdx(0)`.
36- #[ derive( HashStable_Generic ) ]
37- #[ encodable]
38- #[ orderable]
39- pub struct FieldIdx { }
40- }
41-
42- impl FieldIdx {
43- /// The second field, at index 1.
44- ///
45- /// For use alongside [`FieldIdx::ZERO`], particularly with scalar pairs.
46- pub const ONE : FieldIdx = FieldIdx :: from_u32 ( 1 ) ;
47- }
48-
49- rustc_index:: newtype_index! {
50- /// The *source-order* index of a variant in a type.
51- ///
52- /// For enums, these are always `0..variant_count`, regardless of any
53- /// custom discriminants that may have been defined, and including any
54- /// variants that may end up uninhabited due to field types. (Some of the
55- /// variants may not be present in a monomorphized ABI [`Variants`], but
56- /// those skipped variants are always counted when determining the *index*.)
57- ///
58- /// `struct`s, `tuples`, and `unions`s are considered to have a single variant
59- /// with variant index zero, aka [`FIRST_VARIANT`].
60- #[ derive( HashStable_Generic ) ]
61- #[ encodable]
62- #[ orderable]
63- pub struct VariantIdx {
64- /// Equivalent to `VariantIdx(0)`.
65- const FIRST_VARIANT = 0 ;
66- }
67- }
6815#[ derive( Copy , Clone , PartialEq , Eq , Hash , HashStable_Generic ) ]
6916#[ rustc_pass_by_value]
7017pub struct Layout < ' a > ( pub Interned < ' a , LayoutData < FieldIdx , VariantIdx > > ) ;
0 commit comments