Skip to content

Commit b316bcc

Browse files
committed
replace for loops with sth more idiomatic
1 parent 9c62571 commit b316bcc

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

crates/ide-assists/src/handlers/convert_comment_block.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@ fn line_to_block(acc: &mut Assists, comment: ast::Comment) -> Option<()> {
8686
// contents of each line comment when they're put into the block comment.
8787
let indentation = IndentLevel::from_token(comment.syntax());
8888

89-
let mut cms: Vec<String> = Vec::new();
90-
for cm in comments {
91-
let lcm = line_comment_text(indentation, cm)?;
92-
cms.push(lcm);
93-
}
89+
let cms = comments
90+
.into_iter()
91+
.map(|c| line_comment_text(indentation, c))
92+
.collect::<Option<Vec<String>>>()?;
9493

9594
acc.add(
9695
AssistId("line_to_block", AssistKind::RefactorRewrite),

crates/ide-assists/src/handlers/desugar_doc_comment.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub(crate) fn desugar_doc_comment(acc: &mut Assists, ctx: &AssistContext<'_>) ->
5050
(
5151
TextRange::new(
5252
comments[0].syntax().text_range().start(),
53-
comments.last().unwrap().syntax().text_range().end(),
53+
comments.last()?.syntax().text_range().end(),
5454
),
5555
Either::Right(comments),
5656
)
@@ -66,14 +66,11 @@ pub(crate) fn desugar_doc_comment(acc: &mut Assists, ctx: &AssistContext<'_>) ->
6666
.map(|l| l.strip_prefix(&indentation).unwrap_or(l))
6767
.join("\n")
6868
}
69-
Either::Right(comments) => {
70-
let mut cms: Vec<String> = Vec::new();
71-
for cm in comments {
72-
let lcm = line_comment_text(IndentLevel(0), cm)?;
73-
cms.push(lcm);
74-
}
75-
cms.into_iter().join("\n")
76-
}
69+
Either::Right(comments) => comments
70+
.into_iter()
71+
.map(|cm| line_comment_text(IndentLevel(0), cm))
72+
.collect::<Option<Vec<_>>>()?
73+
.join("\n"),
7774
};
7875

7976
acc.add(

0 commit comments

Comments
 (0)