replace for loops with sth more idiomatic

This commit is contained in:
Ali Bektas 2023-08-09 23:34:30 +02:00
parent 9c6257138d
commit b316bccc97
2 changed files with 10 additions and 14 deletions

View file

@ -86,11 +86,10 @@ fn line_to_block(acc: &mut Assists, comment: ast::Comment) -> Option<()> {
// contents of each line comment when they're put into the block comment.
let indentation = IndentLevel::from_token(comment.syntax());
let mut cms: Vec<String> = Vec::new();
for cm in comments {
let lcm = line_comment_text(indentation, cm)?;
cms.push(lcm);
}
let cms = comments
.into_iter()
.map(|c| line_comment_text(indentation, c))
.collect::<Option<Vec<String>>>()?;
acc.add(
AssistId("line_to_block", AssistKind::RefactorRewrite),

View file

@ -50,7 +50,7 @@ pub(crate) fn desugar_doc_comment(acc: &mut Assists, ctx: &AssistContext<'_>) ->
(
TextRange::new(
comments[0].syntax().text_range().start(),
comments.last().unwrap().syntax().text_range().end(),
comments.last()?.syntax().text_range().end(),
),
Either::Right(comments),
)
@ -66,14 +66,11 @@ pub(crate) fn desugar_doc_comment(acc: &mut Assists, ctx: &AssistContext<'_>) ->
.map(|l| l.strip_prefix(&indentation).unwrap_or(l))
.join("\n")
}
Either::Right(comments) => {
let mut cms: Vec<String> = Vec::new();
for cm in comments {
let lcm = line_comment_text(IndentLevel(0), cm)?;
cms.push(lcm);
}
cms.into_iter().join("\n")
}
Either::Right(comments) => comments
.into_iter()
.map(|cm| line_comment_text(IndentLevel(0), cm))
.collect::<Option<Vec<_>>>()?
.join("\n"),
};
acc.add(