File tree Expand file tree Collapse file tree 3 files changed +10
-1
lines changed Expand file tree Collapse file tree 3 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -419,6 +419,7 @@ impl Rewrite for [ast::Attribute] {
419
419
shape. with_max_width ( context. config ) ,
420
420
context,
421
421
0 ,
422
+ false ,
422
423
) ?;
423
424
let comment = if comment. is_empty ( ) {
424
425
format ! ( "\n {}" , mlb)
@@ -449,6 +450,7 @@ impl Rewrite for [ast::Attribute] {
449
450
shape. with_max_width ( context. config ) ,
450
451
context,
451
452
0 ,
453
+ false ,
452
454
) ?;
453
455
result. push_str ( & comment) ;
454
456
if let Some ( next) = attrs. get ( derives. len ( ) ) {
@@ -482,6 +484,7 @@ impl Rewrite for [ast::Attribute] {
482
484
shape. with_max_width ( context. config ) ,
483
485
context,
484
486
0 ,
487
+ false ,
485
488
) ?;
486
489
result. push_str ( & comment) ;
487
490
if let Some ( next) = attrs. get ( 1 ) {
Original file line number Diff line number Diff line change @@ -965,6 +965,7 @@ pub(crate) fn recover_missing_comment_in_span(
965
965
shape : Shape ,
966
966
context : & RewriteContext < ' _ > ,
967
967
used_width : usize ,
968
+ remove_leading_newlines : bool ,
968
969
) -> Option < String > {
969
970
let missing_comment = rewrite_missing_comment ( span, shape, context) ?;
970
971
if missing_comment. is_empty ( ) {
@@ -976,7 +977,9 @@ pub(crate) fn recover_missing_comment_in_span(
976
977
let total_width = missing_comment. len ( ) + used_width + 1 ;
977
978
let force_new_line_before_comment =
978
979
missing_snippet[ ..pos] . contains ( '\n' ) || total_width > context. config . max_width ( ) ;
979
- let sep = if force_new_line_before_comment {
980
+ let sep = if remove_leading_newlines && force_new_line_before_comment {
981
+ shape. indent . to_string ( context. config )
982
+ } else if force_new_line_before_comment {
980
983
shape. indent . to_string_with_newline ( context. config )
981
984
} else {
982
985
Cow :: from ( " " )
Original file line number Diff line number Diff line change @@ -713,6 +713,7 @@ pub(crate) fn format_impl(
713
713
Shape :: indented ( offset, context. config ) ,
714
714
context,
715
715
last_line_width ( & result) ,
716
+ false ,
716
717
) {
717
718
Some ( ref missing_comment) if !missing_comment. is_empty ( ) => {
718
719
result. push_str ( missing_comment) ;
@@ -1092,6 +1093,7 @@ pub(crate) fn format_trait(
1092
1093
Shape :: indented ( offset, context. config ) ,
1093
1094
context,
1094
1095
last_line_width ( & result) ,
1096
+ false ,
1095
1097
) {
1096
1098
Some ( ref missing_comment) if !missing_comment. is_empty ( ) => {
1097
1099
result. push_str ( missing_comment) ;
@@ -2482,6 +2484,7 @@ fn rewrite_fn_base(
2482
2484
shape,
2483
2485
context,
2484
2486
last_line_width ( & result) ,
2487
+ false ,
2485
2488
) {
2486
2489
Some ( ref missing_comment) if !missing_comment. is_empty ( ) => {
2487
2490
result. push_str ( missing_comment) ;
You can’t perform that action at this time.
0 commit comments