Skip to content

Commit 9059713

Browse files
authored
Upgrade to syn v2.0 (#22)
1 parent 2a124b6 commit 9059713

File tree

18 files changed

+417
-350
lines changed

18 files changed

+417
-350
lines changed

Cargo.toml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,14 @@ host = ["dep:rustacuda", "dep:regex", "dep:oneshot", "dep:safer_owning_ref"]
2626
kernel = ["dep:rust-cuda-kernel"]
2727

2828
[dependencies]
29-
rustacuda_core = { git = "https://github.com/juntyr/RustaCUDA", rev = "c6ea7cc" }
30-
31-
rustacuda = { git = "https://github.com/juntyr/RustaCUDA", rev = "c6ea7cc", optional = true }
32-
rustacuda_derive = { git = "https://github.com/juntyr/RustaCUDA", rev = "c6ea7cc", optional = true }
33-
34-
regex = { version = "1.10", optional = true }
35-
36-
const-type-layout = { version = "0.3.2", features = ["derive"] }
37-
38-
safer_owning_ref = { version = "0.5", optional = true }
39-
oneshot = { version = "0.1", optional = true, features = ["std", "async"] }
40-
41-
final = { version = "0.1.1", optional = true }
42-
43-
rust-cuda-derive = { path = "rust-cuda-derive", optional = true }
44-
rust-cuda-kernel = { path = "rust-cuda-kernel", optional = true }
29+
const-type-layout = { version = "0.3.2", default-features = false, features = ["derive"] }
30+
final = { version = "0.1.1", default-features = false, optional = true }
31+
oneshot = { version = "0.1", default-features = false, features = ["std", "async"], optional = true }
32+
regex = { version = "1.10", default-features = false, optional = true }
33+
rustacuda = { git = "https://github.com/juntyr/RustaCUDA", rev = "c6ea7cc", default-features = false, optional = true }
34+
rustacuda_core = { git = "https://github.com/juntyr/RustaCUDA", rev = "c6ea7cc", default-features = false }
35+
rustacuda_derive = { git = "https://github.com/juntyr/RustaCUDA", rev = "c6ea7cc", default-features = false, optional = true }
36+
safer_owning_ref = { version = "0.5", default-features = false, optional = true }
37+
38+
rust-cuda-derive = { path = "rust-cuda-derive", default-features = false, optional = true }
39+
rust-cuda-kernel = { path = "rust-cuda-kernel", default-features = false, optional = true }

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)