mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 14:33:29 +00:00
replace for loops with sth more idiomatic
This commit is contained in:
parent
9c6257138d
commit
b316bccc97
2 changed files with 10 additions and 14 deletions
|
@ -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.
|
// contents of each line comment when they're put into the block comment.
|
||||||
let indentation = IndentLevel::from_token(comment.syntax());
|
let indentation = IndentLevel::from_token(comment.syntax());
|
||||||
|
|
||||||
let mut cms: Vec<String> = Vec::new();
|
let cms = comments
|
||||||
for cm in comments {
|
.into_iter()
|
||||||
let lcm = line_comment_text(indentation, cm)?;
|
.map(|c| line_comment_text(indentation, c))
|
||||||
cms.push(lcm);
|
.collect::<Option<Vec<String>>>()?;
|
||||||
}
|
|
||||||
|
|
||||||
acc.add(
|
acc.add(
|
||||||
AssistId("line_to_block", AssistKind::RefactorRewrite),
|
AssistId("line_to_block", AssistKind::RefactorRewrite),
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub(crate) fn desugar_doc_comment(acc: &mut Assists, ctx: &AssistContext<'_>) ->
|
||||||
(
|
(
|
||||||
TextRange::new(
|
TextRange::new(
|
||||||
comments[0].syntax().text_range().start(),
|
comments[0].syntax().text_range().start(),
|
||||||
comments.last().unwrap().syntax().text_range().end(),
|
comments.last()?.syntax().text_range().end(),
|
||||||
),
|
),
|
||||||
Either::Right(comments),
|
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))
|
.map(|l| l.strip_prefix(&indentation).unwrap_or(l))
|
||||||
.join("\n")
|
.join("\n")
|
||||||
}
|
}
|
||||||
Either::Right(comments) => {
|
Either::Right(comments) => comments
|
||||||
let mut cms: Vec<String> = Vec::new();
|
.into_iter()
|
||||||
for cm in comments {
|
.map(|cm| line_comment_text(IndentLevel(0), cm))
|
||||||
let lcm = line_comment_text(IndentLevel(0), cm)?;
|
.collect::<Option<Vec<_>>>()?
|
||||||
cms.push(lcm);
|
.join("\n"),
|
||||||
}
|
|
||||||
cms.into_iter().join("\n")
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
acc.add(
|
acc.add(
|
||||||
|
|
Loading…
Reference in a new issue