Remove 'Option<_>' from return type of 'take_while_with_pred()'
@@ -797,7 +797,7 @@ fn take_while_with_pred<'a, P>(
context: &RewriteContext,
attrs: &'a [ast::Attribute],
pred: P,
-) -> Option<&'a [ast::Attribute]>
+) -> &'a [ast::Attribute]
where
P: Fn(&ast::Attribute) -> bool,
{
@@ -818,9 +818,9 @@ where
last_index = i;
}
if last_index == 0 {
- None
+ &[]
} else {
- Some(&attrs[..last_index + 1])
+ &attrs[..last_index + 1]
}
}
@@ -833,8 +833,8 @@ fn rewrite_first_group_attrs(
return Some((0, String::new()));
}
// Rewrite doc comments
- match take_while_with_pred(context, attrs, |a| a.is_sugared_doc) {
- Some(sugared_docs) if !sugared_docs.is_empty() => {
+ let sugared_docs = take_while_with_pred(context, attrs, |a| a.is_sugared_doc);
+ if !sugared_docs.is_empty() {
let snippet = sugared_docs
.iter()
.map(|a| context.snippet(a.span))
@@ -845,12 +845,10 @@ fn rewrite_first_group_attrs(
rewrite_comment(&snippet, false, shape, context.config)?,
));
}
- _ => (),
- }
// Rewrite `#[derive(..)]`s.
if context.config.merge_derives() {
- match take_while_with_pred(context, attrs, is_derive) {
- Some(derives) if !derives.is_empty() => {
+ let derives = take_while_with_pred(context, attrs, is_derive);
+ if !derives.is_empty() {
let mut derive_args = vec![];
for derive in derives {
derive_args.append(&mut get_derive_args(context, derive)?);
@@ -860,8 +858,6 @@ fn rewrite_first_group_attrs(
format_derive(context, &derive_args, shape)?,
));
}
- _ => (),
- }
}
// Rewrite the first attribute.
Some((1, attrs[0].rewrite(context, shape)?))
