File tree 2 files changed +5
-13
lines changed
2 files changed +5
-13
lines changed Original file line number Diff line number Diff line change @@ -181,10 +181,7 @@ fn test_doc_comment_multi_line_block_strips_suffix() {
181
181
. ok ( )
182
182
. unwrap ( ) ;
183
183
let module = file. syntax ( ) . descendants ( ) . find_map ( Module :: cast) . unwrap ( ) ;
184
- assert_eq ! (
185
- " this\n is\n mod foo\n " ,
186
- module. doc_comment_text( ) . unwrap( )
187
- ) ;
184
+ assert_eq ! ( " this\n is\n mod foo" , module. doc_comment_text( ) . unwrap( ) ) ;
188
185
}
189
186
190
187
#[ test]
Original file line number Diff line number Diff line change @@ -115,8 +115,8 @@ pub trait DocCommentsOwner: AstNode {
115
115
}
116
116
117
117
/// Returns the textual content of a doc comment block as a single string.
118
- /// That is, strips leading `///` or trailing `*/` (+ optional 1 character of whitespace in either direction)
119
- /// and joins lines.
118
+ /// That is, strips leading `///` (+ optional 1 character of whitespace),
119
+ /// trailing `*/`, trailing whitespace and then joins the lines.
120
120
fn doc_comment_text ( & self ) -> Option < String > {
121
121
let mut has_comments = false ;
122
122
let docs = self
@@ -137,17 +137,12 @@ pub trait DocCommentsOwner: AstNode {
137
137
} ;
138
138
139
139
let end = if comment. kind ( ) . shape . is_block ( ) && line. ends_with ( "*/" ) {
140
- // FIXME: Use `nth_back` here once stable
141
- if line. chars ( ) . rev ( ) . nth ( 2 ) . map ( |c| c. is_whitespace ( ) ) . unwrap_or ( false ) {
142
- line. len ( ) - 3
143
- } else {
144
- line. len ( ) - 2
145
- }
140
+ line. len ( ) - 2
146
141
} else {
147
142
line. len ( )
148
143
} ;
149
144
150
- line[ pos..end] . to_owned ( )
145
+ line[ pos..end] . trim_end ( ) . to_owned ( )
151
146
} )
152
147
. join ( "\n " ) ;
153
148
You can’t perform that action at this time.
0 commit comments