Skip to content

Commit

Permalink
[refactor] #3682: remove direct dependency on syn 1
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Strygin <dcnick3@users.noreply.github.com>
  • Loading branch information
DCNick3 committed Mar 11, 2024
1 parent 96f8410 commit fbade98
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 71 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ test_network = { version = "=2.0.0-pre-rc.20", path = "core/test_network" }

proc-macro-error = "1.0.4"
proc-macro2 = "1.0.69"
syn = { package = "syn", version = "1.0.109", default-features = false }
syn2 = { package = "syn", version = "2.0.38", default-features = false }
quote = "1.0.33"
manyhow = { version = "0.8.1", features = ["darling"] }
Expand Down
1 change: 0 additions & 1 deletion macro/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ is-it-maintained-open-issues = { repository = "https://github.com/hyperledger/ir
maintenance = { status = "actively-developed" }

[dependencies]
syn = { workspace = true, features = ["default", "parsing", "printing"] }
syn2 = { workspace = true, features = ["default", "parsing", "printing"] }
darling = { workspace = true }
quote = { workspace = true }
Expand Down
66 changes: 0 additions & 66 deletions macro/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,6 @@ mod emitter;

pub use emitter::Emitter;

/// Trait for attribute parsing generalization
pub trait AttrParser<Inner: syn::parse::Parse> {
/// Attribute identifier `#[IDENT...]`
const IDENT: &'static str;

/// Parse `Inner` content of attribute
///
/// # Errors
/// - If `Inner` parsing failed
/// - If `IDENT` doesn't match
fn parse(attr: &syn::Attribute) -> syn::Result<Inner> {
attr.path
.is_ident(&<Self as AttrParser<_>>::IDENT)
.then(|| attr.parse_args::<Inner>())
.map_or_else(
|| {
Err(syn::parse::Error::new_spanned(
attr,
format!(
"Attribute must be in form #[{}...]",
<Self as AttrParser<_>>::IDENT
),
))
},
|inner| inner,
)
}
}

/// Macro for automatic [`syn::parse::Parse`] impl generation for keyword
/// attribute structs in derive macros.
#[macro_export]
macro_rules! attr_struct {
// Matching struct with named fields
(
$( #[$meta:meta] )*
// ^~~~attributes~~~~^
$vis:vis struct $name:ident {
$(
$( #[$field_meta:meta] )*
// ^~~~field attributes~~~!^
$field_vis:vis $field_name:ident : $field_ty:ty
// ^~~~~~~~~~~~~~~~~a single field~~~~~~~~~~~~~~~^
),*
$(,)? }
) => {
$( #[$meta] )*
$vis struct $name {
$(
$( #[$field_meta] )*
$field_vis $field_name : $field_ty
),*
}

impl syn::parse::Parse for $name {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
Ok(Self {
$(
$field_name: input.parse()?,
)*
})
}
}
};
}

/// Extension trait for [`darling::Error`].
///
/// Currently exists to add `with_spans` method.
Expand Down
2 changes: 1 addition & 1 deletion schema/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ proc-macro = true
syn2 = { workspace = true, features = ["default", "full"] }
proc-macro2 = { workspace = true }
quote = { workspace = true }
manyhow = { workspace = true, features = ["syn1", "darling"] }
manyhow = { workspace = true, features = ["darling"] }
darling = { workspace = true }

[dev-dependencies]
Expand Down

0 comments on commit fbade98

Please sign in to comment.