@@ -30,7 +30,7 @@ pub use rustc_target::abi::*;
30
30
31
31
pub trait IntegerExt {
32
32
fn to_ty < ' a , ' tcx > ( & self , tcx : TyCtxt < ' a , ' tcx , ' tcx > , signed : bool ) -> Ty < ' tcx > ;
33
- fn from_attr < C : HasDataLayout > ( cx : C , ity : attr:: IntType ) -> Integer ;
33
+ fn from_attr < C : HasDataLayout > ( cx : & C , ity : attr:: IntType ) -> Integer ;
34
34
fn repr_discr < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
35
35
ty : Ty < ' tcx > ,
36
36
repr : & ReprOptions ,
@@ -56,7 +56,7 @@ impl IntegerExt for Integer {
56
56
}
57
57
58
58
/// Get the Integer type from an attr::IntType.
59
- fn from_attr < C : HasDataLayout > ( cx : C , ity : attr:: IntType ) -> Integer {
59
+ fn from_attr < C : HasDataLayout > ( cx : & C , ity : attr:: IntType ) -> Integer {
60
60
let dl = cx. data_layout ( ) ;
61
61
62
62
match ity {
@@ -92,7 +92,7 @@ impl IntegerExt for Integer {
92
92
let min_default = I8 ;
93
93
94
94
if let Some ( ity) = repr. int {
95
- let discr = Integer :: from_attr ( tcx, ity) ;
95
+ let discr = Integer :: from_attr ( & tcx, ity) ;
96
96
let fit = if ity. is_signed ( ) { signed_fit } else { unsigned_fit } ;
97
97
if discr < fit {
98
98
bug ! ( "Integer::repr_discr: `#[repr]` hint too small for \
@@ -202,14 +202,13 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
202
202
} ;
203
203
}
204
204
205
- #[ derive( Copy , Clone ) ]
206
205
pub struct LayoutCx < ' tcx , C > {
207
206
pub tcx : C ,
208
207
pub param_env : ty:: ParamEnv < ' tcx >
209
208
}
210
209
211
210
impl < ' a , ' tcx > LayoutCx < ' tcx , TyCtxt < ' a , ' tcx , ' tcx > > {
212
- fn layout_raw_uncached ( self , ty : Ty < ' tcx > )
211
+ fn layout_raw_uncached ( & self , ty : Ty < ' tcx > )
213
212
-> Result < & ' tcx LayoutDetails , LayoutError < ' tcx > > {
214
213
let tcx = self . tcx ;
215
214
let param_env = self . param_env ;
@@ -899,7 +898,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
899
898
900
899
let ( mut min, mut max) = ( i128:: max_value ( ) , i128:: min_value ( ) ) ;
901
900
let discr_type = def. repr . discr_type ( ) ;
902
- let bits = Integer :: from_attr ( tcx , discr_type) . size ( ) . bits ( ) ;
901
+ let bits = Integer :: from_attr ( self , discr_type) . size ( ) . bits ( ) ;
903
902
for ( i, discr) in def. discriminants ( tcx) . enumerate ( ) {
904
903
if variants[ i] . iter ( ) . any ( |f| f. abi . is_uninhabited ( ) ) {
905
904
continue ;
@@ -1141,7 +1140,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
1141
1140
/// This is invoked by the `layout_raw` query to record the final
1142
1141
/// layout of each type.
1143
1142
#[ inline]
1144
- fn record_layout_for_printing ( self , layout : TyLayout < ' tcx > ) {
1143
+ fn record_layout_for_printing ( & self , layout : TyLayout < ' tcx > ) {
1145
1144
// If we are running with `-Zprint-type-sizes`, record layouts for
1146
1145
// dumping later. Ignore layouts that are done with non-empty
1147
1146
// environments or non-monomorphic layouts, as the user only wants
@@ -1158,7 +1157,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
1158
1157
self . record_layout_for_printing_outlined ( layout)
1159
1158
}
1160
1159
1161
- fn record_layout_for_printing_outlined ( self , layout : TyLayout < ' tcx > ) {
1160
+ fn record_layout_for_printing_outlined ( & self , layout : TyLayout < ' tcx > ) {
1162
1161
// (delay format until we actually need it)
1163
1162
let record = |kind, packed, opt_discr_size, variants| {
1164
1163
let type_desc = format ! ( "{:?}" , layout. ty) ;
@@ -1478,7 +1477,7 @@ impl<'a, 'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
1478
1477
1479
1478
/// Computes the layout of a type. Note that this implicitly
1480
1479
/// executes in "reveal all" mode.
1481
- fn layout_of ( self , ty : Ty < ' tcx > ) -> Self :: TyLayout {
1480
+ fn layout_of ( & self , ty : Ty < ' tcx > ) -> Self :: TyLayout {
1482
1481
let param_env = self . param_env . with_reveal_all ( ) ;
1483
1482
let ty = self . tcx . normalize_erasing_regions ( param_env, ty) ;
1484
1483
let details = self . tcx . layout_raw ( param_env. and ( ty) ) ?;
@@ -1505,7 +1504,7 @@ impl<'a, 'tcx> LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'a, 'tcx, 'tcx>>
1505
1504
1506
1505
/// Computes the layout of a type. Note that this implicitly
1507
1506
/// executes in "reveal all" mode.
1508
- fn layout_of ( self , ty : Ty < ' tcx > ) -> Self :: TyLayout {
1507
+ fn layout_of ( & self , ty : Ty < ' tcx > ) -> Self :: TyLayout {
1509
1508
let param_env = self . param_env . with_reveal_all ( ) ;
1510
1509
let ty = self . tcx . normalize_erasing_regions ( param_env, ty) ;
1511
1510
let details = self . tcx . layout_raw ( param_env. and ( ty) ) ?;
@@ -1563,7 +1562,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
1563
1562
where C : LayoutOf < Ty = Ty < ' tcx > > + HasTyCtxt < ' tcx > ,
1564
1563
C :: TyLayout : MaybeResult < TyLayout < ' tcx > >
1565
1564
{
1566
- fn for_variant ( this : TyLayout < ' tcx > , cx : C , variant_index : usize ) -> TyLayout < ' tcx > {
1565
+ fn for_variant ( this : TyLayout < ' tcx > , cx : & C , variant_index : usize ) -> TyLayout < ' tcx > {
1567
1566
let details = match this. variants {
1568
1567
Variants :: Single { index } if index == variant_index => this. details ,
1569
1568
@@ -1602,7 +1601,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
1602
1601
}
1603
1602
}
1604
1603
1605
- fn field ( this : TyLayout < ' tcx > , cx : C , i : usize ) -> C :: TyLayout {
1604
+ fn field ( this : TyLayout < ' tcx > , cx : & C , i : usize ) -> C :: TyLayout {
1606
1605
let tcx = cx. tcx ( ) ;
1607
1606
cx. layout_of ( match this. ty . sty {
1608
1607
ty:: Bool |
@@ -1699,7 +1698,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
1699
1698
Variants :: Tagged { tag : ref discr, .. } |
1700
1699
Variants :: NicheFilling { niche : ref discr, .. } => {
1701
1700
assert_eq ! ( i, 0 ) ;
1702
- let layout = LayoutDetails :: scalar ( tcx , discr. clone ( ) ) ;
1701
+ let layout = LayoutDetails :: scalar ( cx , discr. clone ( ) ) ;
1703
1702
return MaybeResult :: from_ok ( TyLayout {
1704
1703
details : tcx. intern_layout ( layout) ,
1705
1704
ty : discr. value . to_ty ( tcx)
@@ -1725,7 +1724,7 @@ struct Niche {
1725
1724
impl Niche {
1726
1725
fn reserve < ' a , ' tcx > (
1727
1726
& self ,
1728
- cx : LayoutCx < ' tcx , TyCtxt < ' a , ' tcx , ' tcx > > ,
1727
+ cx : & LayoutCx < ' tcx , TyCtxt < ' a , ' tcx , ' tcx > > ,
1729
1728
count : u128 ,
1730
1729
) -> Option < ( u128 , Scalar ) > {
1731
1730
if count > self . available {
@@ -1745,7 +1744,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
1745
1744
/// Find the offset of a niche leaf field, starting from
1746
1745
/// the given type and recursing through aggregates.
1747
1746
// FIXME(eddyb) traverse already optimized enums.
1748
- fn find_niche ( self , layout : TyLayout < ' tcx > ) -> Result < Option < Niche > , LayoutError < ' tcx > > {
1747
+ fn find_niche ( & self , layout : TyLayout < ' tcx > ) -> Result < Option < Niche > , LayoutError < ' tcx > > {
1749
1748
let scalar_niche = |scalar : & Scalar , offset| {
1750
1749
let Scalar { value, valid_range : ref v } = * scalar;
1751
1750
0 commit comments