@@ -521,83 +521,87 @@ fn parse_attrs_for_checking<'a>(
521521 sym : & ' a Symbols ,
522522 attrs : & ' a [ Attribute ] ,
523523) -> impl Iterator < Item = Result < ( Span , SpirvAttribute ) , ParseAttrError > > + ' a {
524- attrs. iter ( ) . flat_map ( move |attr| {
525- let ( whole_attr_error, args) = match attr {
526- Attribute :: Unparsed ( item) => {
527- // #[...]
528- let s = & item. path . segments ;
529- if s. len ( ) > 1 && s[ 0 ] . name == sym. rust_gpu {
530- // #[rust_gpu ...]
531- if s. len ( ) != 2 || s[ 1 ] . name != sym. spirv {
532- // #[rust_gpu::...] but not #[rust_gpu::spirv]
533- (
534- Some ( Err ( (
524+ attrs
525+ . iter ( )
526+ . map ( move |attr| {
527+ // parse the #[rust_gpu::spirv(...)] attr and return the inner list
528+ match attr {
529+ Attribute :: Unparsed ( item) => {
530+ // #[...]
531+ let s = & item. path . segments ;
532+ if s. len ( ) > 1 && s[ 0 ] . name == sym. rust_gpu {
533+ // #[rust_gpu ...]
534+ if s. len ( ) != 2 || s[ 1 ] . name != sym. spirv {
535+ // #[rust_gpu::...] but not #[rust_gpu::spirv]
536+ Err ( (
535537 attr. span ( ) ,
536538 "unknown `rust_gpu` attribute, expected `rust_gpu::spirv`"
537539 . to_string ( ) ,
538- ) ) ) ,
539- Default :: default ( ) ,
540- )
541- } else if let Some ( args) = attr. meta_item_list ( ) {
542- // #[rust_gpu::spirv(...)]
543- ( None , args)
544- } else {
545- // #[rust_gpu::spirv]
546- (
547- Some ( Err ( (
540+ ) )
541+ } else if let Some ( args) = attr. meta_item_list ( ) {
542+ // #[rust_gpu::spirv(...)]
543+ Ok ( args)
544+ } else {
545+ // #[rust_gpu::spirv]
546+ Err ( (
548547 attr. span ( ) ,
549548 "#[rust_gpu::spirv(..)] attribute must have at least one argument"
550549 . to_string ( ) ,
551- ) ) ) ,
552- Default :: default ( ) ,
553- )
550+ ) )
551+ }
552+ } else {
553+ // #[...] but not #[rust_gpu ...]
554+ Ok ( Default :: default ( ) )
554555 }
555- } else {
556- // #[...] but not #[rust_gpu ...]
557- ( None , Default :: default ( ) )
558556 }
557+ Attribute :: Parsed ( _) => Ok ( Default :: default ( ) ) ,
559558 }
560- Attribute :: Parsed ( _) => ( None , Default :: default ( ) ) ,
561- } ;
562-
563- whole_attr_error
564- . into_iter ( )
565- . chain ( args. into_iter ( ) . map ( move |ref arg| {
566- let span = arg. span ( ) ;
567- let parsed_attr = if arg. has_name ( sym. descriptor_set ) {
568- SpirvAttribute :: DescriptorSet ( parse_attr_int_value ( arg) ?)
569- } else if arg. has_name ( sym. binding ) {
570- SpirvAttribute :: Binding ( parse_attr_int_value ( arg) ?)
571- } else if arg. has_name ( sym. input_attachment_index ) {
572- SpirvAttribute :: InputAttachmentIndex ( parse_attr_int_value ( arg) ?)
573- } else if arg. has_name ( sym. spec_constant ) {
574- SpirvAttribute :: SpecConstant ( parse_spec_constant_attr ( sym, arg) ?)
575- } else {
576- let name = match arg. ident ( ) {
577- Some ( i) => i,
578- None => {
579- return Err ( (
580- span,
581- "#[spirv(..)] attribute argument must be single identifier"
582- . to_string ( ) ,
583- ) ) ;
584- }
559+ } )
560+ . flat_map ( |result| {
561+ // parse each element of the inner list
562+ let ( v, e) = match result {
563+ Ok ( v) => ( Some ( v) , None ) ,
564+ Err ( e) => ( None , Some ( e) ) ,
565+ } ;
566+ v. unwrap_or_default ( )
567+ . into_iter ( )
568+ . map ( |ref arg| {
569+ let span = arg. span ( ) ;
570+ let parsed_attr = if arg. has_name ( sym. descriptor_set ) {
571+ SpirvAttribute :: DescriptorSet ( parse_attr_int_value ( arg) ?)
572+ } else if arg. has_name ( sym. binding ) {
573+ SpirvAttribute :: Binding ( parse_attr_int_value ( arg) ?)
574+ } else if arg. has_name ( sym. input_attachment_index ) {
575+ SpirvAttribute :: InputAttachmentIndex ( parse_attr_int_value ( arg) ?)
576+ } else if arg. has_name ( sym. spec_constant ) {
577+ SpirvAttribute :: SpecConstant ( parse_spec_constant_attr ( sym, arg) ?)
578+ } else {
579+ let name = match arg. ident ( ) {
580+ Some ( i) => i,
581+ None => {
582+ return Err ( (
583+ span,
584+ "#[spirv(..)] attribute argument must be single identifier"
585+ . to_string ( ) ,
586+ ) ) ;
587+ }
588+ } ;
589+ sym. attributes . get ( & name. name ) . map_or_else (
590+ || Err ( ( name. span , "unknown argument to spirv attribute" . to_string ( ) ) ) ,
591+ |a| {
592+ Ok ( match a {
593+ SpirvAttribute :: Entry ( entry) => SpirvAttribute :: Entry (
594+ parse_entry_attrs ( sym, arg, & name, entry. execution_model ) ?,
595+ ) ,
596+ _ => a. clone ( ) ,
597+ } )
598+ } ,
599+ ) ?
585600 } ;
586- sym. attributes . get ( & name. name ) . map_or_else (
587- || Err ( ( name. span , "unknown argument to spirv attribute" . to_string ( ) ) ) ,
588- |a| {
589- Ok ( match a {
590- SpirvAttribute :: Entry ( entry) => SpirvAttribute :: Entry (
591- parse_entry_attrs ( sym, arg, & name, entry. execution_model ) ?,
592- ) ,
593- _ => a. clone ( ) ,
594- } )
595- } ,
596- ) ?
597- } ;
598- Ok ( ( span, parsed_attr) )
599- } ) )
600- } )
601+ Ok ( ( span, parsed_attr) )
602+ } )
603+ . chain ( e. map ( |e| Err ( e) ) )
604+ } )
601605}
602606
603607fn parse_spec_constant_attr (
0 commit comments