@@ -23,77 +23,70 @@ pub fn swap_field_type_and_filter_attrs(
2323
2424 // Remove all attributes from the fields in the Cuda representation
2525 field. attrs . retain ( |attr| {
26- if attr. path . is_ident ( "cuda" ) {
27- if let Ok ( syn:: Meta :: List ( list) ) = attr. parse_meta ( ) {
28- for meta in & list. nested {
29- match meta {
30- syn:: NestedMeta :: Meta ( syn:: Meta :: Path ( path) ) if path. is_ident ( "ignore" ) => {
31- r2c_ignore = true ;
32- } ,
33- syn:: NestedMeta :: Meta ( syn:: Meta :: Path ( path) ) if path. is_ident ( "embed" ) => {
34- if cuda_repr_field_ty. is_none ( ) {
35- cuda_repr_field_ty = Some ( CudaReprFieldTy :: RustToCuda {
36- field_ty : Box :: new ( field_ty. clone ( ) ) ,
37- } ) ;
26+ if attr. path ( ) . is_ident ( "cuda" ) {
27+ if let Err ( err) = attr. parse_nested_meta ( |meta| {
28+ if meta. path . is_ident ( "ignore" ) {
29+ r2c_ignore = true ;
30+ return Ok ( ( ) ) ;
31+ }
32+
33+ if meta. path . is_ident ( "embed" ) {
34+ if cuda_repr_field_ty. is_some ( ) {
35+ emit_error ! (
36+ attr. span( ) ,
37+ "[rust-cuda]: Duplicate #[cuda(embed)] field attribute."
38+ ) ;
39+ return Ok ( ( ) ) ;
40+ }
41+
42+ if let Ok ( meta) = meta. value ( ) {
43+ match meta. parse :: < syn:: LitStr > ( ) . and_then ( |s| syn:: parse_str ( & s. value ( ) ) ) {
44+ Ok ( proxy_ty) => {
45+ let old_field_ty = Box :: new ( field_ty. clone ( ) ) ;
3846 field_ty = parse_quote ! {
3947 #crate_path:: utils:: ffi:: DeviceAccessible <
40- <#field_ty as #crate_path:: lend:: RustToCuda >:: CudaRepresentation
48+ <#proxy_ty as #crate_path:: lend:: RustToCuda >:: CudaRepresentation
4149 >
4250 } ;
43- } else {
44- emit_error ! (
45- attr. span( ) ,
46- "[rust-cuda]: Duplicate #[cuda(embed)] field attribute."
47- ) ;
48- }
49- } ,
50- syn:: NestedMeta :: Meta ( syn:: Meta :: NameValue ( syn:: MetaNameValue {
51- path,
52- lit : syn:: Lit :: Str ( s) ,
53- ..
54- } ) ) if path. is_ident ( "embed" ) => {
55- if cuda_repr_field_ty. is_none ( ) {
56- match syn:: parse_str ( & s. value ( ) ) {
57- Ok ( proxy_ty) => {
58- let old_field_ty = Box :: new ( field_ty. clone ( ) ) ;
59- field_ty = parse_quote ! {
60- #crate_path:: utils:: ffi:: DeviceAccessible <
61- <#proxy_ty as #crate_path:: lend:: RustToCuda >:: CudaRepresentation
62- >
63- } ;
64- cuda_repr_field_ty = Some ( CudaReprFieldTy :: RustToCudaProxy {
65- proxy_ty : Box :: new ( proxy_ty) ,
66- field_ty : old_field_ty,
67- } ) ;
68- } ,
69- Err ( err) => emit_error ! (
70- s. span( ) ,
71- "[rust-cuda]: Invalid #[cuda(embed = \
72- \" <proxy-type>\" )] field attribute: {}.",
73- err
74- ) ,
75- }
76- } else {
77- emit_error ! (
78- attr. span( ) ,
79- "[rust-cuda]: Duplicate #[cuda(embed)] field attribute."
80- ) ;
81- }
82- } ,
83- _ => {
84- emit_error ! (
51+ cuda_repr_field_ty = Some ( CudaReprFieldTy :: RustToCudaProxy {
52+ proxy_ty : Box :: new ( proxy_ty) ,
53+ field_ty : old_field_ty,
54+ } ) ;
55+ } ,
56+ Err ( err) => emit_error ! (
8557 meta. span( ) ,
86- "[rust-cuda]: Expected #[cuda(ignore)] / #[cuda(embed)] / \
87- #[cuda(embed = \" <proxy-type>\" )] field attribute"
88- ) ;
58+ "[rust-cuda]: Invalid #[cuda(embed = \
59+ \" <proxy-type>\" )] field attribute: {}.",
60+ err
61+ ) ,
8962 }
63+ } else {
64+ cuda_repr_field_ty = Some ( CudaReprFieldTy :: RustToCuda {
65+ field_ty : Box :: new ( field_ty. clone ( ) ) ,
66+ } ) ;
67+ field_ty = parse_quote ! {
68+ #crate_path:: utils:: ffi:: DeviceAccessible <
69+ <#field_ty as #crate_path:: lend:: RustToCuda >:: CudaRepresentation
70+ >
71+ } ;
9072 }
73+
74+ return Ok ( ( ) ) ;
9175 }
92- } else {
76+
77+ emit_error ! (
78+ meta. path. span( ) ,
79+ "[rust-cuda]: Expected #[cuda(ignore)] / #[cuda(embed)] / \
80+ #[cuda(embed = \" <proxy-type>\" )] field attribute"
81+ ) ;
82+
83+ Ok ( ( ) )
84+ } ) {
9385 emit_error ! (
9486 attr. span( ) ,
9587 "[rust-cuda]: Expected #[cuda(ignore)] / #[cuda(embed)] / \
96- #[cuda(embed = \" <proxy-type>\" )] field attribute."
88+ #[cuda(embed = \" <proxy-type>\" )] field attribute: {}",
89+ err
9790 ) ;
9891 }
9992
0 commit comments