@@ -8,6 +8,7 @@ use std::ops::{Add, AddAssign, Mul, RangeInclusive, Sub};
88use std:: str:: FromStr ;
99
1010use bitflags:: bitflags;
11+ use rustc_data_structures:: intern:: Interned ;
1112#[ cfg( feature = "nightly" ) ]
1213use rustc_data_structures:: stable_hasher:: StableOrd ;
1314use rustc_index:: vec:: { Idx , IndexVec } ;
@@ -1250,9 +1251,9 @@ impl Abi {
12501251
12511252#[ derive( PartialEq , Eq , Hash , Clone , Debug ) ]
12521253#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
1253- pub enum Variants < V : Idx > {
1254+ pub enum Variants {
12541255 /// Single enum variants, structs/tuples, unions, and all non-ADTs.
1255- Single { index : V } ,
1256+ Single { index : VariantIdx } ,
12561257
12571258 /// Enum-likes with more than one inhabited variant: each variant comes with
12581259 /// a *discriminant* (usually the same as the variant index but the user can
@@ -1262,15 +1263,15 @@ pub enum Variants<V: Idx> {
12621263 /// For enums, the tag is the sole field of the layout.
12631264 Multiple {
12641265 tag : Scalar ,
1265- tag_encoding : TagEncoding < V > ,
1266+ tag_encoding : TagEncoding ,
12661267 tag_field : usize ,
1267- variants : IndexVec < V , LayoutS < V > > ,
1268+ variants : IndexVec < VariantIdx , LayoutS > ,
12681269 } ,
12691270}
12701271
12711272#[ derive( PartialEq , Eq , Hash , Clone , Debug ) ]
12721273#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
1273- pub enum TagEncoding < V : Idx > {
1274+ pub enum TagEncoding {
12741275 /// The tag directly stores the discriminant, but possibly with a smaller layout
12751276 /// (so converting the tag to the discriminant can require sign extension).
12761277 Direct ,
@@ -1285,7 +1286,11 @@ pub enum TagEncoding<V: Idx> {
12851286 /// For example, `Option<(usize, &T)>` is represented such that
12861287 /// `None` has a null pointer for the second tuple field, and
12871288 /// `Some` is the identity function (with a non-null reference).
1288- Niche { untagged_variant : V , niche_variants : RangeInclusive < V > , niche_start : u128 } ,
1289+ Niche {
1290+ untagged_variant : VariantIdx ,
1291+ niche_variants : RangeInclusive < VariantIdx > ,
1292+ niche_start : u128 ,
1293+ } ,
12891294}
12901295
12911296#[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug ) ]
@@ -1372,9 +1377,14 @@ impl Niche {
13721377 }
13731378}
13741379
1380+ rustc_index:: newtype_index! {
1381+ #[ derive( HashStable_Generic ) ]
1382+ pub struct VariantIdx { }
1383+ }
1384+
13751385#[ derive( PartialEq , Eq , Hash , Clone ) ]
13761386#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
1377- pub struct LayoutS < V : Idx > {
1387+ pub struct LayoutS {
13781388 /// Says where the fields are located within the layout.
13791389 pub fields : FieldsShape ,
13801390
@@ -1385,7 +1395,7 @@ pub struct LayoutS<V: Idx> {
13851395 ///
13861396 /// To access all fields of this layout, both `fields` and the fields of the active variant
13871397 /// must be taken into account.
1388- pub variants : Variants < V > ,
1398+ pub variants : Variants ,
13891399
13901400 /// The `abi` defines how this data is passed between functions, and it defines
13911401 /// value restrictions via `valid_range`.
@@ -1404,13 +1414,13 @@ pub struct LayoutS<V: Idx> {
14041414 pub size : Size ,
14051415}
14061416
1407- impl < V : Idx > LayoutS < V > {
1417+ impl LayoutS {
14081418 pub fn scalar < C : HasDataLayout > ( cx : & C , scalar : Scalar ) -> Self {
14091419 let largest_niche = Niche :: from_scalar ( cx, Size :: ZERO , scalar) ;
14101420 let size = scalar. size ( cx) ;
14111421 let align = scalar. align ( cx) ;
14121422 LayoutS {
1413- variants : Variants :: Single { index : V :: new ( 0 ) } ,
1423+ variants : Variants :: Single { index : VariantIdx :: new ( 0 ) } ,
14141424 fields : FieldsShape :: Primitive ,
14151425 abi : Abi :: Scalar ( scalar) ,
14161426 largest_niche,
@@ -1420,7 +1430,7 @@ impl<V: Idx> LayoutS<V> {
14201430 }
14211431}
14221432
1423- impl < V : Idx > fmt:: Debug for LayoutS < V > {
1433+ impl fmt:: Debug for LayoutS {
14241434 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
14251435 // This is how `Layout` used to print before it become
14261436 // `Interned<LayoutS>`. We print it like this to avoid having to update
@@ -1437,6 +1447,43 @@ impl<V: Idx> fmt::Debug for LayoutS<V> {
14371447 }
14381448}
14391449
1450+ #[ derive( Copy , Clone , PartialEq , Eq , Hash , HashStable_Generic ) ]
1451+ #[ rustc_pass_by_value]
1452+ pub struct Layout < ' a > ( pub Interned < ' a , LayoutS > ) ;
1453+
1454+ impl < ' a > fmt:: Debug for Layout < ' a > {
1455+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1456+ // See comment on `<LayoutS as Debug>::fmt` above.
1457+ self . 0 . 0 . fmt ( f)
1458+ }
1459+ }
1460+
1461+ impl < ' a > Layout < ' a > {
1462+ pub fn fields ( self ) -> & ' a FieldsShape {
1463+ & self . 0 . 0 . fields
1464+ }
1465+
1466+ pub fn variants ( self ) -> & ' a Variants {
1467+ & self . 0 . 0 . variants
1468+ }
1469+
1470+ pub fn abi ( self ) -> Abi {
1471+ self . 0 . 0 . abi
1472+ }
1473+
1474+ pub fn largest_niche ( self ) -> Option < Niche > {
1475+ self . 0 . 0 . largest_niche
1476+ }
1477+
1478+ pub fn align ( self ) -> AbiAndPrefAlign {
1479+ self . 0 . 0 . align
1480+ }
1481+
1482+ pub fn size ( self ) -> Size {
1483+ self . 0 . 0 . size
1484+ }
1485+ }
1486+
14401487#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
14411488pub enum PointerKind {
14421489 /// Shared reference. `frozen` indicates the absence of any `UnsafeCell`.
@@ -1464,7 +1511,7 @@ pub enum InitKind {
14641511 UninitMitigated0x01Fill ,
14651512}
14661513
1467- impl < V : Idx > LayoutS < V > {
1514+ impl LayoutS {
14681515 /// Returns `true` if the layout corresponds to an unsized type.
14691516 pub fn is_unsized ( & self ) -> bool {
14701517 self . abi . is_unsized ( )
0 commit comments