@@ -229,6 +229,7 @@ impl<'tcx> ConvSpirvType<'tcx> for CastTarget {
229229            field_types :  args, 
230230            field_offsets, 
231231            field_names :  None , 
232+             is_block :  false , 
232233        } 
233234        . def ( span,  cx) 
234235    } 
@@ -324,6 +325,35 @@ fn trans_type_impl<'tcx>(
324325)  -> Word  { 
325326    if  let  TyKind :: Adt ( adt,  _)  = * ty. ty . kind ( )  { 
326327        for  attr in  parse_attrs ( cx,  cx. tcx . get_attrs ( adt. did ) )  { 
328+             if  matches ! ( attr,  SpirvAttribute :: Block )  { 
329+                 if  !adt. is_struct ( )  { 
330+                     cx. tcx . sess . span_err ( 
331+                         span, 
332+                         & format ! ( 
333+                             "`#[spirv(block)]` can only be used on a `struct`, \  
334+ , 
335+                             ty. ty, 
336+                             adt. descr( ) , 
337+                         ) , 
338+                     ) ; 
339+                 } 
340+ 
341+                 if  !matches ! ( ty. abi,  Abi :: Aggregate  {  sized:  true  } )  { 
342+                     cx. tcx . sess . span_err ( 
343+                         span, 
344+                         & format ! ( 
345+                             "`#[spirv(block)]` can only be used for `Sized` aggregates, \  
346+ , 
347+                             ty. ty,  ty. abi, 
348+                         ) , 
349+                     ) ; 
350+                 } 
351+ 
352+                 assert ! ( matches!( ty. fields,  FieldsShape :: Arbitrary  {  .. } ) ) ; 
353+ 
354+                 return  trans_struct ( cx,  span,  ty,  true ) ; 
355+             } 
356+ 
327357            if  let  Some ( image)  = trans_image ( cx,  span,  ty,  attr)  { 
328358                return  image; 
329359            } 
@@ -340,6 +370,7 @@ fn trans_type_impl<'tcx>(
340370            field_types :  Vec :: new ( ) , 
341371            field_offsets :  Vec :: new ( ) , 
342372            field_names :  None , 
373+             is_block :  false , 
343374        } 
344375        . def ( span,  cx) , 
345376        Abi :: Scalar ( ref  scalar)  => trans_scalar ( cx,  span,  ty,  scalar,  None ,  is_immediate) , 
@@ -359,6 +390,7 @@ fn trans_type_impl<'tcx>(
359390                field_types :  vec ! [ one_spirv,  two_spirv] , 
360391                field_offsets :  vec ! [ one_offset,  two_offset] , 
361392                field_names :  None , 
393+                 is_block :  false , 
362394            } 
363395            . def ( span,  cx) 
364396        } 
@@ -618,6 +650,7 @@ fn trans_aggregate<'tcx>(cx: &CodegenCx<'tcx>, span: Span, ty: TyAndLayout<'tcx>
618650                    field_types :  Vec :: new ( ) , 
619651                    field_offsets :  Vec :: new ( ) , 
620652                    field_names :  None , 
653+                     is_block :  false , 
621654                } 
622655                . def ( span,  cx) 
623656            }  else  { 
@@ -638,7 +671,7 @@ fn trans_aggregate<'tcx>(cx: &CodegenCx<'tcx>, span: Span, ty: TyAndLayout<'tcx>
638671        FieldsShape :: Arbitrary  { 
639672            offsets :  _, 
640673            memory_index :  _, 
641-         }  => trans_struct ( cx,  span,  ty) , 
674+         }  => trans_struct ( cx,  span,  ty,   false ) , 
642675    } 
643676} 
644677
@@ -668,7 +701,12 @@ pub fn auto_struct_layout<'tcx>(
668701} 
669702
670703// see struct_llfields in librustc_codegen_llvm for implementation hints 
671- fn  trans_struct < ' tcx > ( cx :  & CodegenCx < ' tcx > ,  span :  Span ,  ty :  TyAndLayout < ' tcx > )  -> Word  { 
704+ fn  trans_struct < ' tcx > ( 
705+     cx :  & CodegenCx < ' tcx > , 
706+     span :  Span , 
707+     ty :  TyAndLayout < ' tcx > , 
708+     is_block :  bool , 
709+ )  -> Word  { 
672710    let  name = name_of_struct ( ty) ; 
673711    if  let  TyKind :: Foreign ( _)  = ty. ty . kind ( )  { 
674712        // "An unsized FFI type that is opaque to Rust", `extern type A;` (currently unstable) 
@@ -718,6 +756,7 @@ fn trans_struct<'tcx>(cx: &CodegenCx<'tcx>, span: Span, ty: TyAndLayout<'tcx>) -
718756        field_types, 
719757        field_offsets, 
720758        field_names :  Some ( field_names) , 
759+         is_block, 
721760    } 
722761    . def ( span,  cx) 
723762} 
0 commit comments