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

Update syn to v2 #1064

Merged
merged 1 commit into from
Dec 20, 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
37 changes: 24 additions & 13 deletions native/Cargo.lock

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

2 changes: 1 addition & 1 deletion native/libcst_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keywords = ["macros", "python"]
proc-macro = true

[dependencies]
syn = "1.0"
syn = "2.0"
quote = "1.0"

[dev-dependencies]
Expand Down
46 changes: 19 additions & 27 deletions native/libcst_derive/src/cstnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use syn::{
spanned::Spanned,
token::Comma,
AngleBracketedGenericArguments, Attribute, Data, DataEnum, DataStruct, DeriveInput, Field,
Fields, FieldsNamed, FieldsUnnamed, GenericArgument, Generics, Ident, Meta, MetaList,
NestedMeta, Path, PathArguments, PathSegment, Token, Type, TypePath, Visibility,
Fields, FieldsNamed, FieldsUnnamed, GenericArgument, Generics, Ident, Meta, Path,
PathArguments, PathSegment, Token, Type, TypePath, Visibility,
};

pub(crate) struct CSTNodeParams {
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Parse for SupportedTrait {
impl Parse for CSTNodeParams {
fn parse(input: ParseStream) -> syn::Result<Self> {
Ok(Self {
traits: input.parse_terminated(SupportedTrait::parse)?,
traits: input.parse_terminated(SupportedTrait::parse, Token![,])?,
})
}
}
Expand Down Expand Up @@ -239,12 +239,8 @@ fn impl_unnamed_fields(mut deflated_fields: FieldsUnnamed) -> FieldsUnnamed {

// Make sure all Deflated* types have 'r 'a lifetime params
if !added_lifetime {
deflated_fields.unnamed.push(Field {
vis: Visibility::Inherited,
ty: parse_quote!(std::marker::PhantomData<&'r &'a ()>),
attrs: Default::default(),
colon_token: Default::default(),
ident: Default::default(),
deflated_fields.unnamed.push(parse_quote! {
std::marker::PhantomData<&'r &'a ()>
});
}
deflated_fields
Expand Down Expand Up @@ -284,12 +280,8 @@ fn impl_named_fields(mut fields: FieldsNamed) -> (Fields, Fields) {

// Make sure all Deflated* types have 'r 'a lifetime params
if !added_lifetime {
deflated_fields.named.push(Field {
attrs: Default::default(),
vis: Visibility::Inherited,
ident: Some(parse_quote!(_phantom)),
colon_token: Default::default(),
ty: parse_quote!(std::marker::PhantomData<&'r &'a ()>),
deflated_fields.named.push(parse_quote! {
_phantom: std::marker::PhantomData<&'r &'a ()>
});
}

Expand Down Expand Up @@ -411,19 +403,19 @@ fn rightmost_path_segment_mut(ty: &mut Type) -> Option<&mut PathSegment> {
}

fn is_not_intopy_attr(attr: &Attribute) -> bool {
let path = &attr.path;
// support #[cfg_attr(feature="py", skip_py)]
let path = attr.path();
// support #[cfg_attr(feature = "py", skip_py)]
if path.is_ident("cfg_attr") {
match attr.parse_meta() {
Ok(Meta::List(MetaList { nested, .. })) => {
for meta in nested {
if let NestedMeta::Meta(Meta::Path(path)) = meta {
return !is_intopy_attr_path(&path);
}
}
}
_ => return false,
}
return match attr.parse_args_with(|input: ParseStream| {
let _: Meta = input.parse()?;
let _: Token![,] = input.parse()?;
let nested_path: Path = input.parse()?;
let _: Option<Token![,]> = input.parse()?;
Ok(nested_path)
}) {
Ok(nested_path) => !is_intopy_attr_path(&nested_path),
Err(_) => false,
};
}
!is_intopy_attr_path(path)
}
Expand Down
2 changes: 1 addition & 1 deletion native/libcst_derive/src/into_py.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ fn fields_to_kwargs(fields: &Fields, is_enum: bool) -> quote::__private::TokenSt
}

fn has_attr(attrs: &[Attribute], name: &'static str) -> bool {
attrs.iter().any(|attr| attr.path.is_ident(name))
attrs.iter().any(|attr| attr.path().is_ident(name))
}
Loading