diff --git a/derive/Cargo.toml b/derive/Cargo.toml index fb0fcf0..2b73b0d 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -12,4 +12,4 @@ proc_macro = true proc-macro2 = "1.0.47" pulldown-cmark = "0.9.2" quote = "1.0.21" -syn = { version = "1.0.103", features = ["full"] } +syn = { version = "2.0.18 ", features = ["full"] } diff --git a/derive/src/argument.rs b/derive/src/argument.rs index f2f7d2d..06e38e8 100644 --- a/derive/src/argument.rs +++ b/derive/src/argument.rs @@ -2,7 +2,7 @@ use std::ops::RangeInclusive; use proc_macro2::TokenStream; use quote::quote; -use syn::{Attribute, Fields, FieldsUnnamed, Ident, Lit, Meta, Variant}; +use syn::{Attribute, Fields, FieldsUnnamed, Ident, Meta, Variant}; use crate::{ attributes::{parse_argument_attribute, ArgAttr, ArgumentsAttr}, @@ -31,7 +31,7 @@ pub(crate) enum ArgType { pub(crate) fn parse_arguments_attr(attrs: &[Attribute]) -> ArgumentsAttr { for attr in attrs { - if attr.path.is_ident("arguments") { + if attr.path().is_ident("arguments") { return ArgumentsAttr::parse(attr); } } @@ -107,13 +107,21 @@ pub(crate) fn parse_argument(v: Variant) -> Vec { fn collect_help(attrs: &[Attribute]) -> String { let mut help = Vec::new(); for attr in attrs { - let Ok(meta) = attr.parse_meta() else { continue; }; - let Meta::NameValue(name_value) = meta else { continue; }; - if !name_value.path.is_ident("doc") { - continue; + if attr.path().is_ident("doc") { + let value = match &attr.meta { + Meta::NameValue(name_value) => &name_value.value, + _ => panic!("doc attribute must be a name and a value"), + }; + let lit = match value { + syn::Expr::Lit(expr_lit) => &expr_lit.lit, + _ => panic!("argument to doc attribute must be a string literal"), + }; + let litstr = match lit { + syn::Lit::Str(litstr) => litstr, + _ => panic!("argument to doc attribute must be a string literal"), + }; + help.push(litstr.value().trim().to_string()); } - let Lit::Str(litstr) = name_value.lit else { continue; }; - help.push(litstr.value().trim().to_string()) } help.join("\n") } @@ -121,7 +129,7 @@ fn collect_help(attrs: &[Attribute]) -> String { fn get_arg_attributes(attrs: &[Attribute]) -> Vec { attrs .iter() - .filter(|a| a.path.is_ident("option") || a.path.is_ident("positional")) + .filter(|a| a.path().is_ident("option") || a.path().is_ident("positional")) .map(parse_argument_attribute) .collect() } diff --git a/derive/src/attributes.rs b/derive/src/attributes.rs index 3b5e453..4ad29d6 100644 --- a/derive/src/attributes.rs +++ b/derive/src/attributes.rs @@ -14,9 +14,9 @@ pub(crate) enum ArgAttr { } pub(crate) fn parse_argument_attribute(attr: &Attribute) -> ArgAttr { - if attr.path.is_ident("option") { + if attr.path().is_ident("option") { ArgAttr::Option(OptionAttr::parse(attr)) - } else if attr.path.is_ident("positional") { + } else if attr.path().is_ident("positional") { ArgAttr::Positional(PositionalAttr::parse(attr)) } else { panic!("Internal error: invalid argument attribute"); @@ -183,7 +183,7 @@ impl Parse for AttributeArguments { if (input.peek(LitInt) && input.peek2(Token![..])) || input.peek(Token![..]) { // We're dealing with a range let range = input.parse::()?; - let from = match range.from.as_deref() { + let from = match range.start.as_deref() { Some(Expr::Lit(ExprLit { lit: Lit::Int(i), .. })) => i.base10_parse::().unwrap(), @@ -192,7 +192,7 @@ impl Parse for AttributeArguments { }; let inclusive = matches!(range.limits, RangeLimits::Closed(_)); - let to = match range.to.as_deref() { + let to = match range.end.as_deref() { Some(Expr::Lit(ExprLit { lit: Lit::Int(i), .. })) => { diff --git a/derive/src/initial.rs b/derive/src/initial.rs index 2766a1d..f52bdfd 100644 --- a/derive/src/initial.rs +++ b/derive/src/initial.rs @@ -125,7 +125,7 @@ fn initial_struct(data: syn::DataStruct) -> proc_macro2::TokenStream { fn parse_field_attr(attrs: &[Attribute]) -> InitialField { for attr in attrs { - if attr.path.is_ident("initial") { + if attr.path().is_ident("initial") { return InitialField::from_attribute(attr).expect("Failed to parse initial attribute"); } } diff --git a/derive/src/lib.rs b/derive/src/lib.rs index 0f03c4f..ab8b64c 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -129,7 +129,7 @@ pub fn value(input: TokenStream) -> TokenStream { let variant_name = variant.ident.to_string(); let attrs = variant.attrs.clone(); for attr in attrs { - if !attr.path.is_ident("value") { + if !attr.path().is_ident("value") { continue; }