Unnamed repository; edit this file 'description' to name the repository.
replace for loops with sth more idiomatic
Ali Bektas 2023-09-11
parent 9c62571 · commit b316bcc
-rw-r--r--crates/ide-assists/src/handlers/convert_comment_block.rs9
-rw-r--r--crates/ide-assists/src/handlers/desugar_doc_comment.rs15
2 files changed, 10 insertions, 14 deletions
diff --git a/crates/ide-assists/src/handlers/convert_comment_block.rs b/crates/ide-assists/src/handlers/convert_comment_block.rs
index b6ad2dc0b6..4cbb30ec15 100644
--- a/crates/ide-assists/src/handlers/convert_comment_block.rs
+++ b/crates/ide-assists/src/handlers/convert_comment_block.rs
@@ -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),
diff --git a/crates/ide-assists/src/handlers/desugar_doc_comment.rs b/crates/ide-assists/src/handlers/desugar_doc_comment.rs
index daa2c1df0c..2f8cef1e4a 100644
--- a/crates/ide-assists/src/handlers/desugar_doc_comment.rs
+++ b/crates/ide-assists/src/handlers/desugar_doc_comment.rs
@@ -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(