@@ -300,7 +300,24 @@ impl<'a> Formatter<'a> {
300300 self . write_expr_span ( expr) ;
301301 }
302302
303- Expr :: Signature ( sig) => self . format_signature ( sig) ,
303+ Expr :: Signature ( sig) => {
304+ let has_comments = self
305+ . comments
306+ . iter ( )
307+ . any ( |( span, _) | span. start >= expr. span . start && span. end <= expr. span . end ) ;
308+ if has_comments {
309+ self . write_expr_span ( expr) ;
310+ self . last_pos = expr. span . end ;
311+ // Mark comments within the span as written
312+ for ( i, ( span, _) ) in self . comments . iter ( ) . enumerate ( ) {
313+ if span. start >= expr. span . start && span. end <= expr. span . end {
314+ self . written_comments [ i] = true ;
315+ }
316+ }
317+ } else {
318+ self . format_signature ( sig) ;
319+ }
320+ }
304321
305322 Expr :: Call ( call) => self . format_call ( call) ,
306323 Expr :: ExternalCall ( head, args) => self . format_external_call ( head, args) ,
@@ -443,7 +460,22 @@ impl<'a> Formatter<'a> {
443460 fn format_def_argument ( & mut self , positional : & Expression ) {
444461 match & positional. expr {
445462 Expr :: String ( _) => self . format_expression ( positional) ,
446- Expr :: Signature ( sig) => self . format_signature ( sig) ,
463+ Expr :: Signature ( sig) => {
464+ let has_comments = self . comments . iter ( ) . any ( |( span, _) | {
465+ span. start >= positional. span . start && span. end <= positional. span . end
466+ } ) ;
467+ if has_comments {
468+ self . write_expr_span ( positional) ;
469+ // Mark comments within the span as written
470+ for ( i, ( span, _) ) in self . comments . iter ( ) . enumerate ( ) {
471+ if span. start >= positional. span . start && span. end <= positional. span . end {
472+ self . written_comments [ i] = true ;
473+ }
474+ }
475+ } else {
476+ self . format_signature ( sig) ;
477+ }
478+ }
447479 Expr :: Closure ( block_id) | Expr :: Block ( block_id) => {
448480 self . format_block_expression ( * block_id, positional. span , true ) ;
449481 }
0 commit comments