File tree Expand file tree Collapse file tree 3 files changed +49
-5
lines changed Expand file tree Collapse file tree 3 files changed +49
-5
lines changed Original file line number Diff line number Diff line change @@ -1426,12 +1426,22 @@ fn format_empty_struct_or_tuple(
1426
1426
Some ( ref s) if s. is_empty ( ) => ( ) ,
1427
1427
Some ( ref s) => {
1428
1428
if !is_single_line ( s) || first_line_contains_single_line_comment ( s) {
1429
- let nested_indent_str = offset
1430
- . block_indent ( context. config )
1431
- . to_string_with_newline ( context. config ) ;
1432
- result. push_str ( & nested_indent_str) ;
1429
+ // Indent every comment line
1430
+ for l in s. lines ( ) {
1431
+ if l. trim_start ( ) . starts_with ( "//" ) {
1432
+ let nested_indent_str = offset
1433
+ . block_indent ( context. config )
1434
+ . to_string_with_newline ( context. config ) ;
1435
+ result. push_str ( & nested_indent_str) ;
1436
+ } else {
1437
+ result. push ( '\n' ) ;
1438
+ }
1439
+ result. push_str ( l) ;
1440
+ }
1441
+ } else {
1442
+ result. push_str ( s) ;
1433
1443
}
1434
- result . push_str ( s ) ;
1444
+
1435
1445
if last_line_contains_single_line_comment ( s) {
1436
1446
result. push_str ( & offset. to_string_with_newline ( context. config ) ) ;
1437
1447
}
Original file line number Diff line number Diff line change @@ -296,3 +296,20 @@ struct Test {
296
296
// #2818
297
297
struct Paren ( ( i32 ) ) where i32 : Trait ;
298
298
struct Parens ( ( i32 , i32 ) ) where i32 : Trait ;
299
+
300
+ // #4854
301
+ struct Comments {
302
+ // Hello, this is my
303
+ // struct where I haven't added
304
+ // any fields yet.
305
+ // This is weird
306
+ }
307
+
308
+ struct CommentsTup (
309
+ // Ok comment
310
+ // Very good
311
+ // Don't format me pls
312
+
313
+ // With break
314
+ // Yes
315
+ ) ;
Original file line number Diff line number Diff line change @@ -356,3 +356,20 @@ where
356
356
struct Parens ( ( i32 , i32 ) )
357
357
where
358
358
i32 : Trait ;
359
+
360
+ // #4854
361
+ struct Comments {
362
+ // Hello, this is my
363
+ // struct where I haven't added
364
+ // any fields yet.
365
+ // This is weird
366
+ }
367
+
368
+ struct CommentsTup (
369
+ // Ok comment
370
+ // Very good
371
+ // Don't format me pls
372
+
373
+ // With break
374
+ // Yes
375
+ ) ;
You can’t perform that action at this time.
0 commit comments