@@ -399,7 +399,7 @@ impl<'a> FmtVisitor<'a> {
399
399
let context = self . get_context ( ) ;
400
400
401
401
let mut fn_brace_style = newline_for_brace ( self . config , & fn_sig. generics . where_clause ) ;
402
- let ( result, force_newline_brace) =
402
+ let ( result, _ , force_newline_brace) =
403
403
rewrite_fn_base ( & context, indent, ident, fn_sig, span, fn_brace_style) ?;
404
404
405
405
// 2 = ` {`
@@ -425,7 +425,7 @@ impl<'a> FmtVisitor<'a> {
425
425
let span = mk_sp ( span. lo ( ) , span. hi ( ) - BytePos ( 1 ) ) ;
426
426
let context = self . get_context ( ) ;
427
427
428
- let ( mut result, _) = rewrite_fn_base (
428
+ let ( mut result, ends_with_comment , _) = rewrite_fn_base (
429
429
& context,
430
430
indent,
431
431
ident,
@@ -434,6 +434,11 @@ impl<'a> FmtVisitor<'a> {
434
434
FnBraceStyle :: None ,
435
435
) ?;
436
436
437
+ // If `result` ends with a comment, then remember to add a newline
438
+ if ends_with_comment {
439
+ result. push_str ( & indent. to_string_with_newline ( context. config ) ) ;
440
+ }
441
+
437
442
// Re-attach semicolon
438
443
result. push ( ';' ) ;
439
444
@@ -2296,7 +2301,7 @@ fn rewrite_fn_base(
2296
2301
fn_sig : & FnSig < ' _ > ,
2297
2302
span : Span ,
2298
2303
fn_brace_style : FnBraceStyle ,
2299
- ) -> Option < ( String , bool ) > {
2304
+ ) -> Option < ( String , bool , bool ) > {
2300
2305
let mut force_new_line_for_brace = false ;
2301
2306
2302
2307
let where_clause = & fn_sig. generics . where_clause ;
@@ -2601,10 +2606,11 @@ fn rewrite_fn_base(
2601
2606
2602
2607
result. push_str ( & where_clause_str) ;
2603
2608
2604
- force_new_line_for_brace |= last_line_contains_single_line_comment ( & result) ;
2609
+ let ends_with_comment = last_line_contains_single_line_comment ( & result) ;
2610
+ force_new_line_for_brace |= ends_with_comment;
2605
2611
force_new_line_for_brace |=
2606
2612
is_params_multi_lined && context. config . where_single_line ( ) && !where_clause_str. is_empty ( ) ;
2607
- Some ( ( result, force_new_line_for_brace) )
2613
+ Some ( ( result, ends_with_comment , force_new_line_for_brace) )
2608
2614
}
2609
2615
2610
2616
/// Kind of spaces to put before `where`.
@@ -3274,7 +3280,7 @@ impl Rewrite for ast::ForeignItem {
3274
3280
span,
3275
3281
FnBraceStyle :: None ,
3276
3282
)
3277
- . map ( |( s, _) | format ! ( "{};" , s) ) ,
3283
+ . map ( |( s, _, _ ) | format ! ( "{};" , s) ) ,
3278
3284
ast:: ForeignItemKind :: Static ( ref ty, mutability, _) => {
3279
3285
// FIXME(#21): we're dropping potential comments in between the
3280
3286
// function kw here.
0 commit comments