Skip to content

Commit 6a406a8

Browse files
author
Ruben Schmidmeister
committed
Return iterator instead of collecting early
1 parent b875fe9 commit 6a406a8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/attr.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@ fn is_derive(attr: &ast::Attribute) -> bool {
5353
}
5454

5555
/// Returns the arguments of `#[derive(...)]`.
56-
fn get_derive_spans(attr: &ast::Attribute) -> Option<Vec<Span>> {
56+
fn get_derive_spans<'a>(attr: &'a ast::Attribute) -> Option<impl Iterator<Item = Span> + 'a> {
5757
attr.meta_item_list().map(|meta_item_list| {
5858
meta_item_list
59-
.iter()
59+
.into_iter()
6060
.map(|nested_meta_item| nested_meta_item.span)
61-
.collect()
6261
})
6362
}
6463

@@ -411,10 +410,11 @@ impl<'a> Rewrite for [ast::Attribute] {
411410
// Handle derives if we will merge them.
412411
if context.config.merge_derives() && is_derive(&attrs[0]) {
413412
let derives = take_while_with_pred(context, attrs, is_derive);
414-
let mut derive_spans = vec![];
415-
for derive in derives {
416-
derive_spans.append(&mut get_derive_spans(derive)?);
417-
}
413+
let derive_spans: Vec<_> = derives
414+
.iter()
415+
.filter_map(get_derive_spans)
416+
.flatten()
417+
.collect();
418418
let derive_str =
419419
format_derive(&derive_spans, attr_prefix(&attrs[0]), shape, context)?;
420420
result.push_str(&derive_str);

0 commit comments

Comments
 (0)