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

Migrate syn to v2 #382

Merged
merged 1 commit into from
Aug 19, 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 snafu-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ unstable-provider-api = []
proc-macro = true

[dependencies]
syn = { version = "1.0.3", features = ["full"] }
quote = "1.0"
proc-macro2 = "1.0"
syn = { version = "2.0", features = ["full"] }
quote = "1.0.25"
proc-macro2 = "1.0.52"
heck = "0.4"
10 changes: 6 additions & 4 deletions snafu-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1438,27 +1438,29 @@ trait GenericAwareNames {
}

fn provided_generic_lifetimes(&self) -> Vec<proc_macro2::TokenStream> {
use syn::{GenericParam, LifetimeDef};
use syn::{GenericParam, LifetimeParam};

self.generics()
.params
.iter()
.flat_map(|p| match p {
GenericParam::Lifetime(LifetimeDef { lifetime, .. }) => Some(quote! { #lifetime }),
GenericParam::Lifetime(LifetimeParam { lifetime, .. }) => {
Some(quote! { #lifetime })
}
_ => None,
})
.collect()
}

fn provided_generic_names(&self) -> Vec<proc_macro2::TokenStream> {
use syn::{ConstParam, GenericParam, LifetimeDef, TypeParam};
use syn::{ConstParam, GenericParam, LifetimeParam, TypeParam};

self.generics()
.params
.iter()
.map(|p| match p {
GenericParam::Type(TypeParam { ident, .. }) => quote! { #ident },
GenericParam::Lifetime(LifetimeDef { lifetime, .. }) => quote! { #lifetime },
GenericParam::Lifetime(LifetimeParam { lifetime, .. }) => quote! { #lifetime },
GenericParam::Const(ConstParam { ident, .. }) => quote! { #ident },
})
.collect()
Expand Down
9 changes: 6 additions & 3 deletions snafu-derive/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub(crate) fn attributes_from_syn(
let mut errs = Vec::new();

for attr in attrs {
if attr.path.is_ident("snafu") {
if attr.path().is_ident("snafu") {
let attr_list = Punctuated::<Attribute, token::Comma>::parse_terminated;

match attr.parse_args_with(attr_list) {
Expand All @@ -49,11 +49,11 @@ pub(crate) fn attributes_from_syn(
}
Err(e) => errs.push(e),
}
} else if attr.path.is_ident("doc") {
} else if attr.path().is_ident("doc") {
// Ignore any errors that occur while parsing the doc
// comment. This isn't our attribute so we shouldn't
// assume that we know what values are acceptable.
if let Ok(comment) = syn::parse2::<DocComment>(attr.tokens) {
if let Ok(comment) = syn::parse2::<DocComment>(attr.meta.to_token_stream()) {
ours.push(comment.into());
}
}
Expand Down Expand Up @@ -422,6 +422,7 @@ impl ToTokens for Display {
}

struct DocComment {
doc_ident: Ident,
eq_token: token::Eq,
str: LitStr,
}
Expand All @@ -441,6 +442,7 @@ impl From<DocComment> for SnafuAttribute {
impl Parse for DocComment {
fn parse(input: ParseStream) -> Result<Self> {
Ok(Self {
doc_ident: input.parse()?,
eq_token: input.parse()?,
str: input.parse()?,
})
Expand All @@ -449,6 +451,7 @@ impl Parse for DocComment {

impl ToTokens for DocComment {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.doc_ident.to_tokens(tokens);
self.eq_token.to_tokens(tokens);
self.str.to_tokens(tokens);
}
Expand Down