@@ -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 {
@@ -78,7 +76,7 @@ fn line_to_block(acc: &mut Assists, comment: ast::Comment) -> Option<()> {
7876 // Establish the target of our edit based on the comments we found
7977 let target = TextRange :: new (
8078 comments[ 0 ] . syntax ( ) . text_range ( ) . start ( ) ,
81- comments. last ( ) . unwrap ( ) . syntax ( ) . text_range ( ) . end ( ) ,
79+ comments. last ( ) ? . syntax ( ) . text_range ( ) . end ( ) ,
8280 ) ;
8381
8482 acc. add (
@@ -91,8 +89,12 @@ fn line_to_block(acc: &mut Assists, comment: ast::Comment) -> Option<()> {
9189 // contents of each line comment when they're put into the block comment.
9290 let indentation = IndentLevel :: from_token ( comment. syntax ( ) ) ;
9391
94- let block_comment_body =
95- comments. into_iter ( ) . map ( |c| line_comment_text ( indentation, c) ) . join ( "\n " ) ;
92+ let block_comment_body = comments
93+ . into_iter ( )
94+ . map ( |c| line_comment_text ( indentation, c) )
95+ . collect :: < Vec < String > > ( )
96+ . into_iter ( )
97+ . join ( "\n " ) ;
9698
9799 let block_prefix =
98100 CommentKind { shape : CommentShape :: Block , ..comment. kind ( ) } . prefix ( ) ;
@@ -160,7 +162,8 @@ pub(crate) fn relevant_line_comments(comment: &ast::Comment) -> Vec<Comment> {
160162//
161163// But since such comments aren't idiomatic we're okay with this.
162164pub ( crate ) fn line_comment_text ( indentation : IndentLevel , comm : ast:: Comment ) -> String {
163- let contents_without_prefix = comm. text ( ) . strip_prefix ( comm. prefix ( ) ) . unwrap ( ) ;
165+ let text = comm. text ( ) ;
166+ let contents_without_prefix = text. strip_prefix ( comm. prefix ( ) ) . unwrap_or ( text) ;
164167 let contents = contents_without_prefix. strip_prefix ( ' ' ) . unwrap_or ( contents_without_prefix) ;
165168
166169 // Don't add the indentation if the line is empty
0 commit comments