Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade trustfall_derive to syn v2. #411

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ once_cell = "1.17"
ron = "0.8.0"
similar-asserts = "1.4.2"
maplit = "1.0.2"
syn = "2.0"
quote = "1.0"
proc-macro2 = "1.0.51"
4 changes: 2 additions & 2 deletions trustfall/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trustfall"
version = "0.6.0"
version = "0.6.1"
license = "Apache-2.0"
description = "The trustfall query engine, empowering you to query everything."
repository = "https://github.com/obi1kenobi/trustfall"
Expand All @@ -17,7 +17,7 @@ rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
anyhow = { workspace = true }
trustfall_core = { version = "=0.6.0", path = "../trustfall_core" }
trustfall_derive = { version = "=0.3.0", path = "../trustfall_derive" }
trustfall_derive = { version = "=0.3.1", path = "../trustfall_derive" }

[dev-dependencies] # including examples dependencies
ron = { workspace = true }
Expand Down
8 changes: 4 additions & 4 deletions trustfall_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trustfall_derive"
version = "0.3.0"
version = "0.3.1"
license = "Apache-2.0"
description = "Derive macros for the trustfall query engine."
repository = "https://github.com/obi1kenobi/trustfall"
Expand All @@ -15,9 +15,9 @@ authors.workspace = true
proc-macro = true

[dependencies]
quote = "1.0"
syn = "1.0"
proc-macro2 = "1.0.51"
quote = { workspace = true }
syn = { workspace = true }
proc-macro2 = { workspace = true }

[dev-dependencies]
trybuild = "1.0"
Expand Down
66 changes: 17 additions & 49 deletions trustfall_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,57 +249,25 @@ fn generate_conversion_method(variant: &syn::Variant) -> syn::Result<proc_macro2
// Check if we should skip generating the conversion method
// because of a `#[trustfall(skip_conversion)]` attribute on the variant.
for attr in &variant.attrs {
if let Some(ident) = attr.path.get_ident() {
if ident != TRUSTFALL_ATTRIBUTE {
// Not one of our attributes, skip.
continue;
}
if !attr.path().is_ident(TRUSTFALL_ATTRIBUTE) {
// Not one of our attributes, skip.
continue;
}

// If we ever add more attribute contents, here's how to make the parsing smarter:
// https://blog.turbo.fish/proc-macro-parsing/
match attr.parse_meta()? {
syn::Meta::Path { .. } => {
return Err(syn::Error::new_spanned(
attr,
"no arguments found, did you mean `#[trustfall(skip_conversion)]`?",
));
}
syn::Meta::List(values) => {
let mut skipping = false;
for nested in values.nested.iter() {
match nested {
syn::NestedMeta::Meta(syn::Meta::Path(path)) => {
if let Some(ident) = path.get_ident() {
if ident == SKIP_CONVERSION_ATTRIBUTE {
skipping = true;
} else {
return Err(syn::Error::new_spanned(
nested,
"unexpected arguments found, did you mean `#[trustfall(skip_conversion)]`?",
));
}
}
}
_ => {
return Err(syn::Error::new_spanned(
attr,
"unexpected arguments found, did you mean `#[trustfall(skip_conversion)]`?",
));
}
}
}
if skipping {
return Ok(Default::default());
}
}
syn::Meta::NameValue(name_value) => {
return Err(syn::Error::new_spanned(
&name_value.lit,
"unexpected arguments found, did you mean `#[trustfall(skip_conversion)]`?",
));
}
};
let content: syn::Ident = attr.parse_args().map_err(|_| {
syn::Error::new_spanned(
attr,
"unexpected attribute, did you mean `#[trustfall(skip_conversion)]`?",
)
})?;
if content == SKIP_CONVERSION_ATTRIBUTE {
return Ok(Default::default());
} else {
return Err(syn::Error::new_spanned(
attr,
"unexpected attribute, did you mean `#[trustfall(skip_conversion)]`?",
));
}
}

let variant_ident = &variant.ident;
Expand Down
2 changes: 1 addition & 1 deletion trustfall_derive/tests/ui/invalid_attr_as_path_only.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: no arguments found, did you mean `#[trustfall(skip_conversion)]`?
error: unexpected attribute, did you mean `#[trustfall(skip_conversion)]`?
--> tests/ui/invalid_attr_as_path_only.rs:5:5
|
5 | #[trustfall]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unexpected arguments found, did you mean `#[trustfall(skip_conversion)]`?
error: unexpected attribute, did you mean `#[trustfall(skip_conversion)]`?
--> tests/ui/invalid_attr_unexpected_assignment.rs:6:5
|
6 | #[trustfall(skip_conversion = "yes")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: unexpected arguments found, did you mean `#[trustfall(skip_conversion)]`?
--> tests/ui/invalid_attr_unexpected_list_element.rs:5:34
error: unexpected attribute, did you mean `#[trustfall(skip_conversion)]`?
--> tests/ui/invalid_attr_unexpected_list_element.rs:5:5
|
5 | #[trustfall(skip_conversion, unexpected_arg)]
| ^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: unexpected arguments found, did you mean `#[trustfall(skip_conversion)]`?
--> tests/ui/invalid_attr_unexpected_list_element.rs:13:17
error: unexpected attribute, did you mean `#[trustfall(skip_conversion)]`?
--> tests/ui/invalid_attr_unexpected_list_element.rs:13:5
|
13 | #[trustfall(unexpected_arg, skip_conversion)]
| ^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6 changes: 3 additions & 3 deletions trustfall_stubgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ default = ["cli"]
cli = ["dep:clap"]

[dependencies]
quote = "1.0"
syn = "2.0"
proc-macro2 = "1.0.51"
quote = { workspace = true }
syn = { workspace = true }
proc-macro2 = { workspace = true }
trustfall = { path = "../trustfall", version = "0.6.0" }
maplit = { workspace = true }
async-graphql-parser = { workspace = true }
Expand Down