@@ -50,6 +50,13 @@ fn custom_opener(s: &str) -> &str {
50
50
}
51
51
52
52
impl < ' a > CommentStyle < ' a > {
53
+ pub fn is_doc_comment ( & self ) -> bool {
54
+ match * self {
55
+ CommentStyle :: TripleSlash | CommentStyle :: Doc => true ,
56
+ _ => false ,
57
+ }
58
+ }
59
+
53
60
pub fn opener ( & self ) -> & ' a str {
54
61
match * self {
55
62
CommentStyle :: DoubleSlash => "// " ,
@@ -248,14 +255,15 @@ fn _rewrite_comment(
248
255
return light_rewrite_comment ( orig, shape. indent , config, is_doc_comment) ;
249
256
}
250
257
251
- identify_comment ( orig, block_style, shape, config)
258
+ identify_comment ( orig, block_style, shape, config, is_doc_comment )
252
259
}
253
260
254
261
fn identify_comment (
255
262
orig : & str ,
256
263
block_style : bool ,
257
264
shape : Shape ,
258
265
config : & Config ,
266
+ is_doc_comment : bool ,
259
267
) -> Option < String > {
260
268
let style = comment_style ( orig, false ) ;
261
269
let first_group = orig. lines ( )
@@ -267,11 +275,18 @@ fn identify_comment(
267
275
. collect :: < Vec < _ > > ( )
268
276
. join ( "\n " ) ;
269
277
270
- let first_group_str = rewrite_comment_inner ( & first_group, block_style, style, shape, config) ?;
278
+ let first_group_str = rewrite_comment_inner (
279
+ & first_group,
280
+ block_style,
281
+ style,
282
+ shape,
283
+ config,
284
+ is_doc_comment || style. is_doc_comment ( ) ,
285
+ ) ?;
271
286
if rest. is_empty ( ) {
272
287
Some ( first_group_str)
273
288
} else {
274
- identify_comment ( & rest, block_style, shape, config) . map ( |rest_str| {
289
+ identify_comment ( & rest, block_style, shape, config, is_doc_comment ) . map ( |rest_str| {
275
290
format ! (
276
291
"{}\n {}{}" ,
277
292
first_group_str,
@@ -288,6 +303,7 @@ fn rewrite_comment_inner(
288
303
style : CommentStyle ,
289
304
shape : Shape ,
290
305
config : & Config ,
306
+ is_doc_comment : bool ,
291
307
) -> Option < String > {
292
308
let ( opener, closer, line_start) = if block_style {
293
309
CommentStyle :: SingleBullet . to_str_tuplet ( )
@@ -315,7 +331,7 @@ fn rewrite_comment_inner(
315
331
let lines = orig. lines ( )
316
332
. enumerate ( )
317
333
. map ( |( i, mut line) | {
318
- line = line. trim ( ) ;
334
+ line = trim_right_unless_two_whitespaces ( line. trim_left ( ) , is_doc_comment ) ;
319
335
// Drop old closer.
320
336
if i == line_breaks && line. ends_with ( "*/" ) && !line. starts_with ( "//" ) {
321
337
line = line[ ..( line. len ( ) - 2 ) ] . trim_right ( ) ;
0 commit comments