Skip to content

Commit 1b0ff0d

Browse files
authored
Merge branch 'main' into cust
2 parents a681d67 + 9059713 commit 1b0ff0d

File tree

17 files changed

+406
-334
lines changed

17 files changed

+406
-334
lines changed

rust-cuda-derive/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ rust-version = "1.81" # nightly
1212
proc-macro = true
1313

1414
[dependencies]
15-
syn = { version = "1.0", features = ["full", "fold"] }
16-
quote = "1.0"
17-
proc-macro2 = "1.0"
18-
proc-macro-error = "1.0"
15+
proc-macro2 = { version = "1.0", default-features = false }
16+
proc-macro-error2 = { version = "2.0", default-features = false, features = ["syn-error"] }
17+
quote = { version = "1.0", default-features = false }
18+
syn = { version = "2.0", default-features = false, features = ["full", "fold"] }

rust-cuda-derive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
extern crate proc_macro;
4949

5050
#[macro_use]
51-
extern crate proc_macro_error;
51+
extern crate proc_macro_error2;
5252

5353
use proc_macro::TokenStream;
5454

rust-cuda-derive/src/rust_to_cuda/field_ty.rs

Lines changed: 53 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)