Skip to content

Commit 405360a

Browse files
committed
Refactoring: use methods from libsyntax attr module
1 parent 75cb236 commit 405360a

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

src/visitor.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,27 +1056,16 @@ fn format_derive(context: &RewriteContext, derive_args: &[&str], shape: Shape) -
10561056
}
10571057

10581058
fn is_derive(attr: &ast::Attribute) -> bool {
1059-
match attr.meta() {
1060-
Some(meta_item) => match meta_item.node {
1061-
ast::MetaItemKind::List(..) => meta_item.name.as_str() == "derive",
1062-
_ => false,
1063-
},
1064-
_ => false,
1065-
}
1059+
attr.check_name("derive")
10661060
}
10671061

10681062
/// Returns the arguments of `#[derive(...)]`.
10691063
fn get_derive_args<'a>(context: &'a RewriteContext, attr: &ast::Attribute) -> Option<Vec<&'a str>> {
1070-
attr.meta().and_then(|meta_item| match meta_item.node {
1071-
ast::MetaItemKind::List(ref args) if meta_item.name.as_str() == "derive" => {
1072-
// Every argument of `derive` should be `NestedMetaItemKind::Literal`.
1073-
Some(
1074-
args.iter()
1075-
.map(|a| context.snippet(a.span))
1076-
.collect::<Vec<_>>(),
1077-
)
1078-
}
1079-
_ => None,
1064+
attr.meta_item_list().map(|meta_item_list| {
1065+
meta_item_list
1066+
.iter()
1067+
.map(|nested_meta_item| context.snippet(nested_meta_item.span))
1068+
.collect()
10801069
})
10811070
}
10821071

0 commit comments

Comments
 (0)