@@ -302,7 +302,7 @@ impl<'a> FmtVisitor<'a> {
302
302
let context = self . get_context ( ) ;
303
303
304
304
let mut fn_brace_style = newline_for_brace ( self . config , & fn_sig. generics . where_clause ) ;
305
- let ( result, force_newline_brace) =
305
+ let ( result, _ , force_newline_brace) =
306
306
rewrite_fn_base ( & context, indent, ident, fn_sig, span, fn_brace_style) ?;
307
307
308
308
// 2 = ` {`
@@ -328,7 +328,7 @@ impl<'a> FmtVisitor<'a> {
328
328
let span = mk_sp ( span. lo ( ) , span. hi ( ) - BytePos ( 1 ) ) ;
329
329
let context = self . get_context ( ) ;
330
330
331
- let ( mut result, _) = rewrite_fn_base (
331
+ let ( mut result, ends_with_comment , _) = rewrite_fn_base (
332
332
& context,
333
333
indent,
334
334
ident,
@@ -337,6 +337,11 @@ impl<'a> FmtVisitor<'a> {
337
337
FnBraceStyle :: None ,
338
338
) ?;
339
339
340
+ // If `result` ends with a comment, then remember to add a newline
341
+ if ends_with_comment {
342
+ result. push_str ( & indent. to_string_with_newline ( context. config ) ) ;
343
+ }
344
+
340
345
// Re-attach semicolon
341
346
result. push ( ';' ) ;
342
347
@@ -2142,7 +2147,7 @@ fn rewrite_fn_base(
2142
2147
fn_sig : & FnSig < ' _ > ,
2143
2148
span : Span ,
2144
2149
fn_brace_style : FnBraceStyle ,
2145
- ) -> Option < ( String , bool ) > {
2150
+ ) -> Option < ( String , bool , bool ) > {
2146
2151
let mut force_new_line_for_brace = false ;
2147
2152
2148
2153
let where_clause = & fn_sig. generics . where_clause ;
@@ -2450,10 +2455,11 @@ fn rewrite_fn_base(
2450
2455
2451
2456
result. push_str ( & where_clause_str) ;
2452
2457
2453
- force_new_line_for_brace |= last_line_contains_single_line_comment ( & result) ;
2458
+ let ends_with_comment = last_line_contains_single_line_comment ( & result) ;
2459
+ force_new_line_for_brace |= ends_with_comment;
2454
2460
force_new_line_for_brace |=
2455
2461
is_params_multi_lined && context. config . where_single_line ( ) && !where_clause_str. is_empty ( ) ;
2456
- Some ( ( result, force_new_line_for_brace) )
2462
+ Some ( ( result, ends_with_comment , force_new_line_for_brace) )
2457
2463
}
2458
2464
2459
2465
/// Kind of spaces to put before `where`.
@@ -3137,7 +3143,7 @@ impl Rewrite for ast::ForeignItem {
3137
3143
span,
3138
3144
FnBraceStyle :: None ,
3139
3145
)
3140
- . map ( |( s, _) | format ! ( "{};" , s) ) ,
3146
+ . map ( |( s, _, _ ) | format ! ( "{};" , s) ) ,
3141
3147
ast:: ForeignItemKind :: Static ( ref ty, mutability, _) => {
3142
3148
// FIXME(#21): we're dropping potential comments in between the
3143
3149
// function kw here.
0 commit comments