Skip to content

Commit 2fdf7e4

Browse files
committed
v3
1 parent a66dbd1 commit 2fdf7e4

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ pub(crate) fn convert_comment_block(acc: &mut Assists, ctx: &AssistContext<'_>)
2525
let comment = ctx.find_token_at_offset::<ast::Comment>()?;
2626
// Only allow comments which are alone on their line
2727
if let Some(prev) = comment.syntax().prev_token() {
28-
if Whitespace::cast(prev).filter(|w| w.text().contains('\n')).is_none() {
29-
return None;
30-
}
28+
Whitespace::cast(prev).filter(|w| w.text().contains('\n'))?;
3129
}
3230

3331
match comment.kind().shape {
@@ -86,10 +84,8 @@ fn line_to_block(acc: &mut Assists, comment: ast::Comment) -> Option<()> {
8684
// contents of each line comment when they're put into the block comment.
8785
let indentation = IndentLevel::from_token(comment.syntax());
8886

89-
let cms = comments
90-
.into_iter()
91-
.map(|c| line_comment_text(indentation, c))
92-
.collect::<Option<Vec<String>>>()?;
87+
let cms =
88+
comments.into_iter().map(|c| line_comment_text(indentation, c)).collect::<Vec<String>>();
9389

9490
acc.add(
9591
AssistId("line_to_block", AssistKind::RefactorRewrite),
@@ -163,16 +159,16 @@ pub(crate) fn relevant_line_comments(comment: &ast::Comment) -> Vec<Comment> {
163159
// */
164160
//
165161
// But since such comments aren't idiomatic we're okay with this.
166-
pub(crate) fn line_comment_text(indentation: IndentLevel, comm: ast::Comment) -> Option<String> {
162+
pub(crate) fn line_comment_text(indentation: IndentLevel, comm: ast::Comment) -> String {
167163
let text = comm.text();
168164
let contents_without_prefix = text.strip_prefix(comm.prefix()).unwrap_or(text);
169165
let contents = contents_without_prefix.strip_prefix(' ').unwrap_or(contents_without_prefix);
170166

171167
// Don't add the indentation if the line is empty
172168
if contents.is_empty() {
173-
Some(contents.to_owned())
169+
contents.to_owned()
174170
} else {
175-
Some(indentation.to_string() + contents)
171+
indentation.to_string() + contents
176172
}
177173
}
178174

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ pub(crate) fn desugar_doc_comment(acc: &mut Assists, ctx: &AssistContext<'_>) ->
3333

3434
// Only allow comments which are alone on their line
3535
if let Some(prev) = comment.syntax().prev_token() {
36-
if Whitespace::cast(prev).filter(|w| w.text().contains('\n')).is_none() {
37-
return None;
38-
}
36+
Whitespace::cast(prev).filter(|w| w.text().contains('\n'))?;
3937
}
4038

4139
let indentation = IndentLevel::from_token(comment.syntax()).to_string();
@@ -69,7 +67,7 @@ pub(crate) fn desugar_doc_comment(acc: &mut Assists, ctx: &AssistContext<'_>) ->
6967
Either::Right(comments) => comments
7068
.into_iter()
7169
.map(|cm| line_comment_text(IndentLevel(0), cm))
72-
.collect::<Option<Vec<_>>>()?
70+
.collect::<Vec<_>>()
7371
.join("\n"),
7472
};
7573

0 commit comments

Comments
 (0)