Skip to content

Commit

Permalink
chore(derive): Update syn
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Mar 18, 2023
1 parent e030426 commit 062622f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 43 deletions.
43 changes: 27 additions & 16 deletions 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 clap_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ proc-macro = true
bench = false

[dependencies]
syn = { version = "1.0.74", features = ["full"] }
syn = { version = "2.0.8", features = ["full"] }
quote = "1.0.9"
proc-macro2 = "1.0.42"
heck = "0.4.0"
Expand Down
26 changes: 13 additions & 13 deletions clap_derive/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ impl ClapAttr {
pub fn parse_all(all_attrs: &[Attribute]) -> Result<Vec<Self>, syn::Error> {
let mut parsed = Vec::new();
for attr in all_attrs {
let kind = if attr.path.is_ident("clap") {
Sp::new(AttrKind::Clap, attr.path.span())
} else if attr.path.is_ident("structopt") {
Sp::new(AttrKind::StructOpt, attr.path.span())
} else if attr.path.is_ident("command") {
Sp::new(AttrKind::Command, attr.path.span())
} else if attr.path.is_ident("group") {
Sp::new(AttrKind::Group, attr.path.span())
} else if attr.path.is_ident("arg") {
Sp::new(AttrKind::Arg, attr.path.span())
} else if attr.path.is_ident("value") {
Sp::new(AttrKind::Value, attr.path.span())
let kind = if attr.path().is_ident("clap") {
Sp::new(AttrKind::Clap, attr.path().span())
} else if attr.path().is_ident("structopt") {
Sp::new(AttrKind::StructOpt, attr.path().span())
} else if attr.path().is_ident("command") {
Sp::new(AttrKind::Command, attr.path().span())
} else if attr.path().is_ident("group") {
Sp::new(AttrKind::Group, attr.path().span())
} else if attr.path().is_ident("arg") {
Sp::new(AttrKind::Arg, attr.path().span())
} else if attr.path().is_ident("value") {
Sp::new(AttrKind::Value, attr.path().span())
} else {
continue;
};
Expand Down Expand Up @@ -126,7 +126,7 @@ impl Parse for ClapAttr {
let nested;
parenthesized!(nested in input);

let method_args: Punctuated<_, Token![,]> = nested.parse_terminated(Expr::parse)?;
let method_args: Punctuated<_, _> = nested.parse_terminated(Expr::parse, Token![,])?;
Some(AttrValue::Call(Vec::from_iter(method_args)))
} else {
None
Expand Down
24 changes: 13 additions & 11 deletions clap_derive/src/utils/doc_comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@
use std::iter;

pub fn extract_doc_comment(attrs: &[syn::Attribute]) -> Vec<String> {
use syn::Lit::*;
use syn::Meta::*;
use syn::MetaNameValue;

// multiline comments (`/** ... */`) may have LFs (`\n`) in them,
// we need to split so we could handle the lines correctly
//
// we also need to remove leading and trailing blank lines
let mut lines: Vec<_> = attrs
.iter()
.filter(|attr| attr.path.is_ident("doc"))
.filter(|attr| attr.path().is_ident("doc"))
.filter_map(|attr| {
if let Ok(NameValue(MetaNameValue { lit: Str(s), .. })) = attr.parse_meta() {
Some(s.value())
} else {
// non #[doc = "..."] attributes are not our concern
// we leave them for rustc to handle
None
// non #[doc = "..."] attributes are not our concern
// we leave them for rustc to handle
match &attr.meta {
syn::Meta::NameValue(syn::MetaNameValue {
value:
syn::Expr::Lit(syn::ExprLit {
lit: syn::Lit::Str(s),
..
}),
..
}) => Some(s.value()),
_ => None,
}
})
.skip_while(|s| is_blank(s))
Expand Down
4 changes: 2 additions & 2 deletions tests/derive_ui/clap_empty_attr.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: expected attribute arguments in parentheses: #[command(...)]
--> tests/derive_ui/clap_empty_attr.rs:4:1
--> tests/derive_ui/clap_empty_attr.rs:4:3
|
4 | #[command]
| ^^^^^^^^^^
| ^^^^^^^

error: expected parentheses: #[arg(...)]
--> tests/derive_ui/clap_empty_attr.rs:9:11
Expand Down

0 comments on commit 062622f

Please sign in to comment.