@@ -30,7 +30,7 @@ pub use rustc_target::abi::*;
3030
3131pub trait IntegerExt {
3232 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 ;
3434 fn repr_discr < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
3535 ty : Ty < ' tcx > ,
3636 repr : & ReprOptions ,
@@ -56,7 +56,7 @@ impl IntegerExt for Integer {
5656 }
5757
5858 /// 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 {
6060 let dl = cx. data_layout ( ) ;
6161
6262 match ity {
@@ -92,7 +92,7 @@ impl IntegerExt for Integer {
9292 let min_default = I8 ;
9393
9494 if let Some ( ity) = repr. int {
95- let discr = Integer :: from_attr ( tcx, ity) ;
95+ let discr = Integer :: from_attr ( & tcx, ity) ;
9696 let fit = if ity. is_signed ( ) { signed_fit } else { unsigned_fit } ;
9797 if discr < fit {
9898 bug ! ( "Integer::repr_discr: `#[repr]` hint too small for \
@@ -202,14 +202,13 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
202202 } ;
203203}
204204
205- #[ derive( Copy , Clone ) ]
206205pub struct LayoutCx < ' tcx , C > {
207206 pub tcx : C ,
208207 pub param_env : ty:: ParamEnv < ' tcx >
209208}
210209
211210impl < ' 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 > )
213212 -> Result < & ' tcx LayoutDetails , LayoutError < ' tcx > > {
214213 let tcx = self . tcx ;
215214 let param_env = self . param_env ;
@@ -899,7 +898,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
899898
900899 let ( mut min, mut max) = ( i128:: max_value ( ) , i128:: min_value ( ) ) ;
901900 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 ( ) ;
903902 for ( i, discr) in def. discriminants ( tcx) . enumerate ( ) {
904903 if variants[ i] . iter ( ) . any ( |f| f. abi . is_uninhabited ( ) ) {
905904 continue ;
@@ -1141,7 +1140,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
11411140 /// This is invoked by the `layout_raw` query to record the final
11421141 /// layout of each type.
11431142 #[ inline]
1144- fn record_layout_for_printing ( self , layout : TyLayout < ' tcx > ) {
1143+ fn record_layout_for_printing ( & self , layout : TyLayout < ' tcx > ) {
11451144 // If we are running with `-Zprint-type-sizes`, record layouts for
11461145 // dumping later. Ignore layouts that are done with non-empty
11471146 // environments or non-monomorphic layouts, as the user only wants
@@ -1158,7 +1157,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
11581157 self . record_layout_for_printing_outlined ( layout)
11591158 }
11601159
1161- fn record_layout_for_printing_outlined ( self , layout : TyLayout < ' tcx > ) {
1160+ fn record_layout_for_printing_outlined ( & self , layout : TyLayout < ' tcx > ) {
11621161 // (delay format until we actually need it)
11631162 let record = |kind, packed, opt_discr_size, variants| {
11641163 let type_desc = format ! ( "{:?}" , layout. ty) ;
@@ -1478,7 +1477,7 @@ impl<'a, 'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
14781477
14791478 /// Computes the layout of a type. Note that this implicitly
14801479 /// 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 {
14821481 let param_env = self . param_env . with_reveal_all ( ) ;
14831482 let ty = self . tcx . normalize_erasing_regions ( param_env, ty) ;
14841483 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>>
15051504
15061505 /// Computes the layout of a type. Note that this implicitly
15071506 /// 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 {
15091508 let param_env = self . param_env . with_reveal_all ( ) ;
15101509 let ty = self . tcx . normalize_erasing_regions ( param_env, ty) ;
15111510 let details = self . tcx . layout_raw ( param_env. and ( ty) ) ?;
@@ -1563,7 +1562,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
15631562 where C : LayoutOf < Ty = Ty < ' tcx > > + HasTyCtxt < ' tcx > ,
15641563 C :: TyLayout : MaybeResult < TyLayout < ' tcx > >
15651564{
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 > {
15671566 let details = match this. variants {
15681567 Variants :: Single { index } if index == variant_index => this. details ,
15691568
@@ -1602,7 +1601,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
16021601 }
16031602 }
16041603
1605- fn field ( this : TyLayout < ' tcx > , cx : C , i : usize ) -> C :: TyLayout {
1604+ fn field ( this : TyLayout < ' tcx > , cx : & C , i : usize ) -> C :: TyLayout {
16061605 let tcx = cx. tcx ( ) ;
16071606 cx. layout_of ( match this. ty . sty {
16081607 ty:: Bool |
@@ -1699,7 +1698,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
16991698 Variants :: Tagged { tag : ref discr, .. } |
17001699 Variants :: NicheFilling { niche : ref discr, .. } => {
17011700 assert_eq ! ( i, 0 ) ;
1702- let layout = LayoutDetails :: scalar ( tcx , discr. clone ( ) ) ;
1701+ let layout = LayoutDetails :: scalar ( cx , discr. clone ( ) ) ;
17031702 return MaybeResult :: from_ok ( TyLayout {
17041703 details : tcx. intern_layout ( layout) ,
17051704 ty : discr. value . to_ty ( tcx)
@@ -1725,7 +1724,7 @@ struct Niche {
17251724impl Niche {
17261725 fn reserve < ' a , ' tcx > (
17271726 & self ,
1728- cx : LayoutCx < ' tcx , TyCtxt < ' a , ' tcx , ' tcx > > ,
1727+ cx : & LayoutCx < ' tcx , TyCtxt < ' a , ' tcx , ' tcx > > ,
17291728 count : u128 ,
17301729 ) -> Option < ( u128 , Scalar ) > {
17311730 if count > self . available {
@@ -1745,7 +1744,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
17451744 /// Find the offset of a niche leaf field, starting from
17461745 /// the given type and recursing through aggregates.
17471746 // 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 > > {
17491748 let scalar_niche = |scalar : & Scalar , offset| {
17501749 let Scalar { value, valid_range : ref v } = * scalar;
17511750
0 commit comments