@@ -25,9 +25,7 @@ pub(crate) fn convert_comment_block(acc: &mut Assists, ctx: &AssistContext<'_>)
25
25
let comment = ctx. find_token_at_offset :: < ast:: Comment > ( ) ?;
26
26
// Only allow comments which are alone on their line
27
27
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' ) ) ?;
31
29
}
32
30
33
31
match comment. kind ( ) . shape {
@@ -86,10 +84,8 @@ fn line_to_block(acc: &mut Assists, comment: ast::Comment) -> Option<()> {
86
84
// contents of each line comment when they're put into the block comment.
87
85
let indentation = IndentLevel :: from_token ( comment. syntax ( ) ) ;
88
86
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 > > ( ) ;
93
89
94
90
acc. add (
95
91
AssistId ( "line_to_block" , AssistKind :: RefactorRewrite ) ,
@@ -163,16 +159,16 @@ pub(crate) fn relevant_line_comments(comment: &ast::Comment) -> Vec<Comment> {
163
159
// */
164
160
//
165
161
// 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 {
167
163
let text = comm. text ( ) ;
168
164
let contents_without_prefix = text. strip_prefix ( comm. prefix ( ) ) . unwrap_or ( text) ;
169
165
let contents = contents_without_prefix. strip_prefix ( ' ' ) . unwrap_or ( contents_without_prefix) ;
170
166
171
167
// Don't add the indentation if the line is empty
172
168
if contents. is_empty ( ) {
173
- Some ( contents. to_owned ( ) )
169
+ contents. to_owned ( )
174
170
} else {
175
- Some ( indentation. to_string ( ) + contents)
171
+ indentation. to_string ( ) + contents
176
172
}
177
173
}
178
174
0 commit comments