@@ -270,7 +270,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
270
270
fn univariant_uninterned (
271
271
& self ,
272
272
ty : Ty < ' tcx > ,
273
- fields : & [ TyLayout < ' _ > ] ,
273
+ fields : & [ TyAndLayout < ' _ > ] ,
274
274
repr : & ReprOptions ,
275
275
kind : StructKind ,
276
276
) -> Result < Layout , LayoutError < ' tcx > > {
@@ -293,7 +293,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
293
293
let end =
294
294
if let StructKind :: MaybeUnsized = kind { fields. len ( ) - 1 } else { fields. len ( ) } ;
295
295
let optimizing = & mut inverse_memory_index[ ..end] ;
296
- let field_align = |f : & TyLayout < ' _ > | {
296
+ let field_align = |f : & TyAndLayout < ' _ > | {
297
297
if let Some ( pack) = pack { f. align . abi . min ( pack) } else { f. align . abi }
298
298
} ;
299
299
match kind {
@@ -422,11 +422,15 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
422
422
(
423
423
Some ( (
424
424
i,
425
- & TyLayout { layout : & Layout { abi : Abi :: Scalar ( ref a) , .. } , .. } ,
425
+ & TyAndLayout {
426
+ layout : & Layout { abi : Abi :: Scalar ( ref a) , .. } , ..
427
+ } ,
426
428
) ) ,
427
429
Some ( (
428
430
j,
429
- & TyLayout { layout : & Layout { abi : Abi :: Scalar ( ref b) , .. } , .. } ,
431
+ & TyAndLayout {
432
+ layout : & Layout { abi : Abi :: Scalar ( ref b) , .. } , ..
433
+ } ,
430
434
) ) ,
431
435
None ,
432
436
) => {
@@ -485,7 +489,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
485
489
} ;
486
490
let scalar = |value : Primitive | tcx. intern_layout ( Layout :: scalar ( self , scalar_unit ( value) ) ) ;
487
491
488
- let univariant = |fields : & [ TyLayout < ' _ > ] , repr : & ReprOptions , kind| {
492
+ let univariant = |fields : & [ TyAndLayout < ' _ > ] , repr : & ReprOptions , kind| {
489
493
Ok ( tcx. intern_layout ( self . univariant_uninterned ( ty, fields, repr, kind) ?) )
490
494
} ;
491
495
debug_assert ! ( !ty. has_infer_types_or_consts( ) ) ;
@@ -754,7 +758,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
754
758
// but *not* an encoding of the discriminant (e.g., a tag value).
755
759
// See issue #49298 for more details on the need to leave space
756
760
// for non-ZST uninhabited data (mostly partial initialization).
757
- let absent = |fields : & [ TyLayout < ' _ > ] | {
761
+ let absent = |fields : & [ TyAndLayout < ' _ > ] | {
758
762
let uninhabited = fields. iter ( ) . any ( |f| f. abi . is_uninhabited ( ) ) ;
759
763
let is_zst = fields. iter ( ) . all ( |f| f. is_zst ( ) ) ;
760
764
uninhabited && is_zst
@@ -1404,7 +1408,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
1404
1408
let discr_int_ty = discr_int. to_ty ( tcx, false ) ;
1405
1409
let discr = Scalar { value : Primitive :: Int ( discr_int, false ) , valid_range : 0 ..=max_discr } ;
1406
1410
let discr_layout = self . tcx . intern_layout ( Layout :: scalar ( self , discr. clone ( ) ) ) ;
1407
- let discr_layout = TyLayout { ty : discr_int_ty, layout : discr_layout } ;
1411
+ let discr_layout = TyAndLayout { ty : discr_int_ty, layout : discr_layout } ;
1408
1412
1409
1413
let promoted_layouts = ineligible_locals
1410
1414
. iter ( )
@@ -1573,15 +1577,15 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
1573
1577
/// This is invoked by the `layout_raw` query to record the final
1574
1578
/// layout of each type.
1575
1579
#[ inline( always) ]
1576
- fn record_layout_for_printing ( & self , layout : TyLayout < ' tcx > ) {
1580
+ fn record_layout_for_printing ( & self , layout : TyAndLayout < ' tcx > ) {
1577
1581
// If we are running with `-Zprint-type-sizes`, maybe record layouts
1578
1582
// for dumping later.
1579
1583
if self . tcx . sess . opts . debugging_opts . print_type_sizes {
1580
1584
self . record_layout_for_printing_outlined ( layout)
1581
1585
}
1582
1586
}
1583
1587
1584
- fn record_layout_for_printing_outlined ( & self , layout : TyLayout < ' tcx > ) {
1588
+ fn record_layout_for_printing_outlined ( & self , layout : TyAndLayout < ' tcx > ) {
1585
1589
// Ignore layouts that are done with non-empty environments or
1586
1590
// non-monomorphic layouts, as the user only wants to see the stuff
1587
1591
// resulting from the final codegen session.
@@ -1624,7 +1628,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
1624
1628
let adt_kind = adt_def. adt_kind ( ) ;
1625
1629
let adt_packed = adt_def. repr . pack . is_some ( ) ;
1626
1630
1627
- let build_variant_info = |n : Option < Ident > , flds : & [ ast:: Name ] , layout : TyLayout < ' tcx > | {
1631
+ let build_variant_info = |n : Option < Ident > ,
1632
+ flds : & [ ast:: Name ] ,
1633
+ layout : TyAndLayout < ' tcx > | {
1628
1634
let mut min_size = Size :: ZERO ;
1629
1635
let field_info: Vec < _ > = flds
1630
1636
. iter ( )
@@ -1891,19 +1897,19 @@ impl<'tcx, T: HasTyCtxt<'tcx>> HasTyCtxt<'tcx> for LayoutCx<'tcx, T> {
1891
1897
}
1892
1898
}
1893
1899
1894
- pub type TyLayout < ' tcx > = :: rustc_target:: abi:: TyLayout < ' tcx , Ty < ' tcx > > ;
1900
+ pub type TyAndLayout < ' tcx > = :: rustc_target:: abi:: TyAndLayout < ' tcx , Ty < ' tcx > > ;
1895
1901
1896
1902
impl < ' tcx > LayoutOf for LayoutCx < ' tcx , TyCtxt < ' tcx > > {
1897
1903
type Ty = Ty < ' tcx > ;
1898
- type TyLayout = Result < TyLayout < ' tcx > , LayoutError < ' tcx > > ;
1904
+ type TyAndLayout = Result < TyAndLayout < ' tcx > , LayoutError < ' tcx > > ;
1899
1905
1900
1906
/// Computes the layout of a type. Note that this implicitly
1901
1907
/// executes in "reveal all" mode.
1902
- fn layout_of ( & self , ty : Ty < ' tcx > ) -> Self :: TyLayout {
1908
+ fn layout_of ( & self , ty : Ty < ' tcx > ) -> Self :: TyAndLayout {
1903
1909
let param_env = self . param_env . with_reveal_all ( ) ;
1904
1910
let ty = self . tcx . normalize_erasing_regions ( param_env, ty) ;
1905
1911
let layout = self . tcx . layout_raw ( param_env. and ( ty) ) ?;
1906
- let layout = TyLayout { ty, layout } ;
1912
+ let layout = TyAndLayout { ty, layout } ;
1907
1913
1908
1914
// N.B., this recording is normally disabled; when enabled, it
1909
1915
// can however trigger recursive invocations of `layout_of`.
@@ -1919,15 +1925,15 @@ impl<'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'tcx>> {
1919
1925
1920
1926
impl LayoutOf for LayoutCx < ' tcx , ty:: query:: TyCtxtAt < ' tcx > > {
1921
1927
type Ty = Ty < ' tcx > ;
1922
- type TyLayout = Result < TyLayout < ' tcx > , LayoutError < ' tcx > > ;
1928
+ type TyAndLayout = Result < TyAndLayout < ' tcx > , LayoutError < ' tcx > > ;
1923
1929
1924
1930
/// Computes the layout of a type. Note that this implicitly
1925
1931
/// executes in "reveal all" mode.
1926
- fn layout_of ( & self , ty : Ty < ' tcx > ) -> Self :: TyLayout {
1932
+ fn layout_of ( & self , ty : Ty < ' tcx > ) -> Self :: TyAndLayout {
1927
1933
let param_env = self . param_env . with_reveal_all ( ) ;
1928
1934
let ty = self . tcx . normalize_erasing_regions ( param_env, ty) ;
1929
1935
let layout = self . tcx . layout_raw ( param_env. and ( ty) ) ?;
1930
- let layout = TyLayout { ty, layout } ;
1936
+ let layout = TyAndLayout { ty, layout } ;
1931
1937
1932
1938
// N.B., this recording is normally disabled; when enabled, it
1933
1939
// can however trigger recursive invocations of `layout_of`.
@@ -1950,7 +1956,7 @@ impl TyCtxt<'tcx> {
1950
1956
pub fn layout_of (
1951
1957
self ,
1952
1958
param_env_and_ty : ty:: ParamEnvAnd < ' tcx , Ty < ' tcx > > ,
1953
- ) -> Result < TyLayout < ' tcx > , LayoutError < ' tcx > > {
1959
+ ) -> Result < TyAndLayout < ' tcx > , LayoutError < ' tcx > > {
1954
1960
let cx = LayoutCx { tcx : self , param_env : param_env_and_ty. param_env } ;
1955
1961
cx. layout_of ( param_env_and_ty. value )
1956
1962
}
@@ -1963,19 +1969,23 @@ impl ty::query::TyCtxtAt<'tcx> {
1963
1969
pub fn layout_of (
1964
1970
self ,
1965
1971
param_env_and_ty : ty:: ParamEnvAnd < ' tcx , Ty < ' tcx > > ,
1966
- ) -> Result < TyLayout < ' tcx > , LayoutError < ' tcx > > {
1972
+ ) -> Result < TyAndLayout < ' tcx > , LayoutError < ' tcx > > {
1967
1973
let cx = LayoutCx { tcx : self . at ( self . span ) , param_env : param_env_and_ty. param_env } ;
1968
1974
cx. layout_of ( param_env_and_ty. value )
1969
1975
}
1970
1976
}
1971
1977
1972
- impl < ' tcx , C > TyLayoutMethods < ' tcx , C > for Ty < ' tcx >
1978
+ impl < ' tcx , C > TyAndLayoutMethods < ' tcx , C > for Ty < ' tcx >
1973
1979
where
1974
- C : LayoutOf < Ty = Ty < ' tcx > , TyLayout : MaybeResult < TyLayout < ' tcx > > >
1980
+ C : LayoutOf < Ty = Ty < ' tcx > , TyAndLayout : MaybeResult < TyAndLayout < ' tcx > > >
1975
1981
+ HasTyCtxt < ' tcx >
1976
1982
+ HasParamEnv < ' tcx > ,
1977
1983
{
1978
- fn for_variant ( this : TyLayout < ' tcx > , cx : & C , variant_index : VariantIdx ) -> TyLayout < ' tcx > {
1984
+ fn for_variant (
1985
+ this : TyAndLayout < ' tcx > ,
1986
+ cx : & C ,
1987
+ variant_index : VariantIdx ,
1988
+ ) -> TyAndLayout < ' tcx > {
1979
1989
let layout = match this. variants {
1980
1990
Variants :: Single { index }
1981
1991
// If all variants but one are uninhabited, the variant layout is the enum layout.
@@ -2013,14 +2023,14 @@ where
2013
2023
2014
2024
assert_eq ! ( layout. variants, Variants :: Single { index: variant_index } ) ;
2015
2025
2016
- TyLayout { ty : this. ty , layout }
2026
+ TyAndLayout { ty : this. ty , layout }
2017
2027
}
2018
2028
2019
- fn field ( this : TyLayout < ' tcx > , cx : & C , i : usize ) -> C :: TyLayout {
2029
+ fn field ( this : TyAndLayout < ' tcx > , cx : & C , i : usize ) -> C :: TyAndLayout {
2020
2030
let tcx = cx. tcx ( ) ;
2021
- let discr_layout = |discr : & Scalar | -> C :: TyLayout {
2031
+ let discr_layout = |discr : & Scalar | -> C :: TyAndLayout {
2022
2032
let layout = Layout :: scalar ( cx, discr. clone ( ) ) ;
2023
- MaybeResult :: from ( Ok ( TyLayout {
2033
+ MaybeResult :: from ( Ok ( TyAndLayout {
2024
2034
layout : tcx. intern_layout ( layout) ,
2025
2035
ty : discr. value . to_ty ( tcx) ,
2026
2036
} ) )
@@ -2037,7 +2047,7 @@ where
2037
2047
| ty:: FnDef ( ..)
2038
2048
| ty:: GeneratorWitness ( ..)
2039
2049
| ty:: Foreign ( ..)
2040
- | ty:: Dynamic ( ..) => bug ! ( "TyLayout ::field_type({:?}): not applicable" , this) ,
2050
+ | ty:: Dynamic ( ..) => bug ! ( "TyAndLayout ::field_type({:?}): not applicable" , this) ,
2041
2051
2042
2052
// Potentially-fat pointers.
2043
2053
ty:: Ref ( _, pointee, _) | ty:: RawPtr ( ty:: TypeAndMut { ty : pointee, .. } ) => {
@@ -2080,7 +2090,7 @@ where
2080
2090
])
2081
2091
*/
2082
2092
}
2083
- _ => bug ! ( "TyLayout ::field_type({:?}): not applicable" , this) ,
2093
+ _ => bug ! ( "TyAndLayout ::field_type({:?}): not applicable" , this) ,
2084
2094
}
2085
2095
}
2086
2096
@@ -2132,11 +2142,11 @@ where
2132
2142
| ty:: Opaque ( ..)
2133
2143
| ty:: Param ( _)
2134
2144
| ty:: Infer ( _)
2135
- | ty:: Error => bug ! ( "TyLayout ::field_type: unexpected type `{}`" , this. ty) ,
2145
+ | ty:: Error => bug ! ( "TyAndLayout ::field_type: unexpected type `{}`" , this. ty) ,
2136
2146
} )
2137
2147
}
2138
2148
2139
- fn pointee_info_at ( this : TyLayout < ' tcx > , cx : & C , offset : Size ) -> Option < PointeeInfo > {
2149
+ fn pointee_info_at ( this : TyAndLayout < ' tcx > , cx : & C , offset : Size ) -> Option < PointeeInfo > {
2140
2150
match this. ty . kind {
2141
2151
ty:: RawPtr ( mt) if offset. bytes ( ) == 0 => {
2142
2152
cx. layout_of ( mt. ty ) . to_result ( ) . ok ( ) . map ( |layout| PointeeInfo {
@@ -2337,7 +2347,7 @@ impl<'tcx> ty::Instance<'tcx> {
2337
2347
2338
2348
pub trait FnAbiExt < ' tcx , C >
2339
2349
where
2340
- C : LayoutOf < Ty = Ty < ' tcx > , TyLayout = TyLayout < ' tcx > >
2350
+ C : LayoutOf < Ty = Ty < ' tcx > , TyAndLayout = TyAndLayout < ' tcx > >
2341
2351
+ HasDataLayout
2342
2352
+ HasTargetSpec
2343
2353
+ HasTyCtxt < ' tcx >
@@ -2368,7 +2378,7 @@ where
2368
2378
2369
2379
impl < ' tcx , C > FnAbiExt < ' tcx , C > for call:: FnAbi < ' tcx , Ty < ' tcx > >
2370
2380
where
2371
- C : LayoutOf < Ty = Ty < ' tcx > , TyLayout = TyLayout < ' tcx > >
2381
+ C : LayoutOf < Ty = Ty < ' tcx > , TyAndLayout = TyAndLayout < ' tcx > >
2372
2382
+ HasDataLayout
2373
2383
+ HasTargetSpec
2374
2384
+ HasTyCtxt < ' tcx >
@@ -2518,7 +2528,7 @@ where
2518
2528
// Handle safe Rust thin and fat pointers.
2519
2529
let adjust_for_rust_scalar = |attrs : & mut ArgAttributes ,
2520
2530
scalar : & Scalar ,
2521
- layout : TyLayout < ' tcx > ,
2531
+ layout : TyAndLayout < ' tcx > ,
2522
2532
offset : Size ,
2523
2533
is_return : bool | {
2524
2534
// Booleans are always an i1 that needs to be zero-extended.
0 commit comments