11//! Compute the binary representation of a type
22
3- use std:: sync:: Arc ;
4-
53use base_db:: CrateId ;
64use chalk_ir:: { AdtId , TyKind } ;
75use hir_def:: {
@@ -31,19 +29,19 @@ mod adt;
3129mod target;
3230
3331struct LayoutCx < ' a > {
34- db : & ' a dyn HirDatabase ,
3532 krate : CrateId ,
33+ target : & ' a TargetDataLayout ,
3634}
3735
38- impl LayoutCalculator for LayoutCx < ' _ > {
39- type TargetDataLayoutRef = Arc < TargetDataLayout > ;
36+ impl < ' a > LayoutCalculator for LayoutCx < ' a > {
37+ type TargetDataLayoutRef = & ' a TargetDataLayout ;
4038
4139 fn delay_bug ( & self , txt : & str ) {
4240 never ! ( "{}" , txt) ;
4341 }
4442
45- fn current_data_layout ( & self ) -> Arc < TargetDataLayout > {
46- self . db . target_data_layout ( self . krate )
43+ fn current_data_layout ( & self ) -> & ' a TargetDataLayout {
44+ self . target
4745 }
4846}
4947
@@ -56,7 +54,8 @@ fn scalar(dl: &TargetDataLayout, value: Primitive) -> Layout {
5654}
5755
5856pub fn layout_of_ty ( db : & dyn HirDatabase , ty : & Ty , krate : CrateId ) -> Result < Layout , LayoutError > {
59- let cx = LayoutCx { db, krate } ;
57+ let Some ( target) = db. target_data_layout ( krate) else { return Err ( LayoutError :: TargetLayoutNotAvailable ) } ;
58+ let cx = LayoutCx { krate, target : & target } ;
6059 let dl = & * cx. current_data_layout ( ) ;
6160 Ok ( match ty. kind ( Interner ) {
6261 TyKind :: Adt ( AdtId ( def) , subst) => db. layout_of_adt ( * def, subst. clone ( ) ) ?,
0 commit comments