Skip to content

Commit bd46fda

Browse files
authored
Upgrade trustfall_derive to syn v2. (#411)
* Upgrade `trustfall_derive` to `syn` v2. * fmt
1 parent 81297d8 commit bd46fda

File tree

9 files changed

+40
-69
lines changed

9 files changed

+40
-69
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ once_cell = "1.17"
3838
ron = "0.8.0"
3939
similar-asserts = "1.4.2"
4040
maplit = "1.0.2"
41+
syn = "2.0"
42+
quote = "1.0"
43+
proc-macro2 = "1.0.51"

trustfall/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "trustfall"
3-
version = "0.6.0"
3+
version = "0.6.1"
44
license = "Apache-2.0"
55
description = "The trustfall query engine, empowering you to query everything."
66
repository = "https://github.com/obi1kenobi/trustfall"
@@ -17,7 +17,7 @@ rustdoc-args = ["--cfg", "docsrs"]
1717
[dependencies]
1818
anyhow = { workspace = true }
1919
trustfall_core = { version = "=0.6.0", path = "../trustfall_core" }
20-
trustfall_derive = { version = "=0.3.0", path = "../trustfall_derive" }
20+
trustfall_derive = { version = "=0.3.1", path = "../trustfall_derive" }
2121

2222
[dev-dependencies] # including examples dependencies
2323
ron = { workspace = true }

trustfall_derive/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "trustfall_derive"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
license = "Apache-2.0"
55
description = "Derive macros for the trustfall query engine."
66
repository = "https://github.com/obi1kenobi/trustfall"
@@ -15,9 +15,9 @@ authors.workspace = true
1515
proc-macro = true
1616

1717
[dependencies]
18-
quote = "1.0"
19-
syn = "1.0"
20-
proc-macro2 = "1.0.51"
18+
quote = { workspace = true }
19+
syn = { workspace = true }
20+
proc-macro2 = { workspace = true }
2121

2222
[dev-dependencies]
2323
trybuild = "1.0"

trustfall_derive/src/lib.rs

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -249,57 +249,25 @@ fn generate_conversion_method(variant: &syn::Variant) -> syn::Result<proc_macro2
249249
// Check if we should skip generating the conversion method
250250
// because of a `#[trustfall(skip_conversion)]` attribute on the variant.
251251
for attr in &variant.attrs {
252-
if let Some(ident) = attr.path.get_ident() {
253-
if ident != TRUSTFALL_ATTRIBUTE {
254-
// Not one of our attributes, skip.
255-
continue;
256-
}
252+
if !attr.path().is_ident(TRUSTFALL_ATTRIBUTE) {
253+
// Not one of our attributes, skip.
254+
continue;
257255
}
258256

259-
// If we ever add more attribute contents, here's how to make the parsing smarter:
260-
// https://blog.turbo.fish/proc-macro-parsing/
261-
match attr.parse_meta()? {
262-
syn::Meta::Path { .. } => {
263-
return Err(syn::Error::new_spanned(
264-
attr,
265-
"no arguments found, did you mean `#[trustfall(skip_conversion)]`?",
266-
));
267-
}
268-
syn::Meta::List(values) => {
269-
let mut skipping = false;
270-
for nested in values.nested.iter() {
271-
match nested {
272-
syn::NestedMeta::Meta(syn::Meta::Path(path)) => {
273-
if let Some(ident) = path.get_ident() {
274-
if ident == SKIP_CONVERSION_ATTRIBUTE {
275-
skipping = true;
276-
} else {
277-
return Err(syn::Error::new_spanned(
278-
nested,
279-
"unexpected arguments found, did you mean `#[trustfall(skip_conversion)]`?",
280-
));
281-
}
282-
}
283-
}
284-
_ => {
285-
return Err(syn::Error::new_spanned(
286-
attr,
287-
"unexpected arguments found, did you mean `#[trustfall(skip_conversion)]`?",
288-
));
289-
}
290-
}
291-
}
292-
if skipping {
293-
return Ok(Default::default());
294-
}
295-
}
296-
syn::Meta::NameValue(name_value) => {
297-
return Err(syn::Error::new_spanned(
298-
&name_value.lit,
299-
"unexpected arguments found, did you mean `#[trustfall(skip_conversion)]`?",
300-
));
301-
}
302-
};
257+
let content: syn::Ident = attr.parse_args().map_err(|_| {
258+
syn::Error::new_spanned(
259+
attr,
260+
"unexpected attribute, did you mean `#[trustfall(skip_conversion)]`?",
261+
)
262+
})?;
263+
if content == SKIP_CONVERSION_ATTRIBUTE {
264+
return Ok(Default::default());
265+
} else {
266+
return Err(syn::Error::new_spanned(
267+
attr,
268+
"unexpected attribute, did you mean `#[trustfall(skip_conversion)]`?",
269+
));
270+
}
303271
}
304272

305273
let variant_ident = &variant.ident;

trustfall_derive/tests/ui/invalid_attr_as_path_only.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: no arguments found, did you mean `#[trustfall(skip_conversion)]`?
1+
error: unexpected attribute, did you mean `#[trustfall(skip_conversion)]`?
22
--> tests/ui/invalid_attr_as_path_only.rs:5:5
33
|
44
5 | #[trustfall]

trustfall_derive/tests/ui/invalid_attr_unexpected_assignment.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unexpected arguments found, did you mean `#[trustfall(skip_conversion)]`?
1+
error: unexpected attribute, did you mean `#[trustfall(skip_conversion)]`?
22
--> tests/ui/invalid_attr_unexpected_assignment.rs:6:5
33
|
44
6 | #[trustfall(skip_conversion = "yes")]
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error: unexpected arguments found, did you mean `#[trustfall(skip_conversion)]`?
2-
--> tests/ui/invalid_attr_unexpected_list_element.rs:5:34
1+
error: unexpected attribute, did you mean `#[trustfall(skip_conversion)]`?
2+
--> tests/ui/invalid_attr_unexpected_list_element.rs:5:5
33
|
44
5 | #[trustfall(skip_conversion, unexpected_arg)]
5-
| ^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

7-
error: unexpected arguments found, did you mean `#[trustfall(skip_conversion)]`?
8-
--> tests/ui/invalid_attr_unexpected_list_element.rs:13:17
7+
error: unexpected attribute, did you mean `#[trustfall(skip_conversion)]`?
8+
--> tests/ui/invalid_attr_unexpected_list_element.rs:13:5
99
|
1010
13 | #[trustfall(unexpected_arg, skip_conversion)]
11-
| ^^^^^^^^^^^^^^
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

trustfall_stubgen/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ default = ["cli"]
2020
cli = ["dep:clap"]
2121

2222
[dependencies]
23-
quote = "1.0"
24-
syn = "2.0"
25-
proc-macro2 = "1.0.51"
23+
quote = { workspace = true }
24+
syn = { workspace = true }
25+
proc-macro2 = { workspace = true }
2626
trustfall = { path = "../trustfall", version = "0.6.0" }
2727
maplit = { workspace = true }
2828
async-graphql-parser = { workspace = true }

0 commit comments

Comments
 (0)