diff options
author | Kirill Chibisov <contact@kchibisov.com> | 2023-05-16 08:57:39 +0300 |
---|---|---|
committer | Kirill Chibisov <contact@kchibisov.com> | 2023-05-17 08:36:41 +0300 |
commit | 6f6ad2b2eec9dbc9b3a1b0190d4a2dfd3c0b3bf6 (patch) | |
tree | 7bf2ac2542e2c4c601fc085d021e44601d8260b0 /alacritty_config_derive | |
parent | 04811c674ba01a0f68d9842c33816b78fe3253ab (diff) | |
download | alacritty-6f6ad2b2eec9dbc9b3a1b0190d4a2dfd3c0b3bf6.tar.gz alacritty-6f6ad2b2eec9dbc9b3a1b0190d4a2dfd3c0b3bf6.zip |
Update clap to v4.2.7
Fixes #6879.
Fixes #6874.
Diffstat (limited to 'alacritty_config_derive')
-rw-r--r-- | alacritty_config_derive/Cargo.toml | 2 | ||||
-rw-r--r-- | alacritty_config_derive/src/config_deserialize/de_enum.rs | 10 | ||||
-rw-r--r-- | alacritty_config_derive/src/config_deserialize/de_struct.rs | 4 | ||||
-rw-r--r-- | alacritty_config_derive/src/lib.rs | 8 |
4 files changed, 13 insertions, 11 deletions
diff --git a/alacritty_config_derive/Cargo.toml b/alacritty_config_derive/Cargo.toml index 6c7104ce..437e351d 100644 --- a/alacritty_config_derive/Cargo.toml +++ b/alacritty_config_derive/Cargo.toml @@ -12,7 +12,7 @@ rust-version = "1.60.0" proc-macro = true [dependencies] -syn = { version = "1.0.53", features = ["derive", "parsing", "proc-macro", "printing"], default-features = false } +syn = { version = "2.0.16", features = ["derive", "parsing", "proc-macro", "printing"], default-features = false } proc-macro2 = "1.0.24" quote = "1.0.7" diff --git a/alacritty_config_derive/src/config_deserialize/de_enum.rs b/alacritty_config_derive/src/config_deserialize/de_enum.rs index 56a2f7ba..f94977ae 100644 --- a/alacritty_config_derive/src/config_deserialize/de_enum.rs +++ b/alacritty_config_derive/src/config_deserialize/de_enum.rs @@ -1,6 +1,7 @@ use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; use quote::{format_ident, quote}; +use syn::meta::ParseNestedMeta; use syn::{DataEnum, Generics, Ident}; use crate::serde_replace; @@ -14,7 +15,14 @@ pub fn derive_deserialize(ident: Ident, generics: Generics, data_enum: DataEnum) for variant in data_enum.variants.iter().filter(|variant| { // Skip deserialization for `#[config(skip)]` fields. variant.attrs.iter().all(|attr| { - !crate::path_ends_with(&attr.path, "config") || attr.tokens.to_string() != "(skip)" + let is_skip = |meta: ParseNestedMeta| { + if meta.path.is_ident("skip") { + Ok(()) + } else { + Err(meta.error("not skip")) + } + }; + !attr.path().is_ident("config") || attr.parse_nested_meta(is_skip).is_err() }) }) { let variant_ident = &variant.ident; diff --git a/alacritty_config_derive/src/config_deserialize/de_struct.rs b/alacritty_config_derive/src/config_deserialize/de_struct.rs index 4245764f..1846f925 100644 --- a/alacritty_config_derive/src/config_deserialize/de_struct.rs +++ b/alacritty_config_derive/src/config_deserialize/de_struct.rs @@ -115,7 +115,7 @@ fn field_deserializer(field_streams: &mut FieldStreams, field: &Field) -> Result }; // Iterate over all #[config(...)] attributes. - for attr in field.attrs.iter().filter(|attr| crate::path_ends_with(&attr.path, "config")) { + for attr in field.attrs.iter().filter(|attr| attr.path().is_ident("config")) { let parsed = match attr.parse_args::<Attr>() { Ok(parsed) => parsed, Err(_) => continue, @@ -161,7 +161,7 @@ fn field_deserializer(field_streams: &mut FieldStreams, field: &Field) -> Result // Create token stream for deserializing "none" string into `Option<T>`. if let Type::Path(type_path) = &field.ty { - if crate::path_ends_with(&type_path.path, "Option") { + if type_path.path.segments.iter().last().map_or(false, |s| s.ident == "Option") { match_assignment_stream = quote! { if value.as_str().map_or(false, |s| s.eq_ignore_ascii_case("none")) { config.#ident = None; diff --git a/alacritty_config_derive/src/lib.rs b/alacritty_config_derive/src/lib.rs index 116d4828..a7850529 100644 --- a/alacritty_config_derive/src/lib.rs +++ b/alacritty_config_derive/src/lib.rs @@ -6,7 +6,7 @@ use proc_macro2::TokenStream as TokenStream2; use quote::quote; use syn::parse::{self, Parse, ParseStream}; use syn::punctuated::Punctuated; -use syn::{GenericParam, Ident, LitStr, Path, Token, TypeParam}; +use syn::{GenericParam, Ident, LitStr, Token, TypeParam}; mod config_deserialize; mod serde_replace; @@ -25,12 +25,6 @@ pub fn derive_serde_replace(input: TokenStream) -> TokenStream { serde_replace::derive(input) } -/// Verify that a token path ends with a specific segment. -pub(crate) fn path_ends_with(path: &Path, segment: &str) -> bool { - let segments = path.segments.iter(); - segments.last().map_or(false, |s| s.ident == segment) -} - /// Storage for all necessary generics information. #[derive(Default)] struct GenericsStreams { |