@@ -36,7 +36,7 @@ const DEFAULT_VISIBILITY: ast::Visibility = source_map::Spanned {
3636} ;
3737
3838fn type_annotation_separator ( config : & Config ) -> & str {
39- colon_spaces ( config. space_before_colon ( ) , config . space_after_colon ( ) )
39+ colon_spaces ( config)
4040}
4141
4242// Statements of the form
@@ -1695,10 +1695,7 @@ fn rewrite_static(
16951695 static_parts : & StaticParts < ' _ > ,
16961696 offset : Indent ,
16971697) -> Option < String > {
1698- let colon = colon_spaces (
1699- context. config . space_before_colon ( ) ,
1700- context. config . space_after_colon ( ) ,
1701- ) ;
1698+ let colon = colon_spaces ( context. config ) ;
17021699 let mut prefix = format ! (
17031700 "{}{}{} {}{}{}" ,
17041701 format_visibility( context, static_parts. vis) ,
@@ -1828,6 +1825,42 @@ fn is_empty_infer(ty: &ast::Ty, pat_span: Span) -> bool {
18281825 }
18291826}
18301827
1828+ /// Recover any missing comments between the argument and the type.
1829+ ///
1830+ /// # Returns
1831+ ///
1832+ /// A 2-len tuple with the comment before the colon in first position, and the comment after the
1833+ /// colon in second position.
1834+ fn get_missing_arg_comments (
1835+ context : & RewriteContext < ' _ > ,
1836+ pat_span : Span ,
1837+ ty_span : Span ,
1838+ shape : Shape ,
1839+ ) -> ( String , String ) {
1840+ let missing_comment_span = mk_sp ( pat_span. hi ( ) , ty_span. lo ( ) ) ;
1841+
1842+ let span_before_colon = {
1843+ let missing_comment_span_hi = context
1844+ . snippet_provider
1845+ . span_before ( missing_comment_span, ":" ) ;
1846+ mk_sp ( pat_span. hi ( ) , missing_comment_span_hi)
1847+ } ;
1848+ let span_after_colon = {
1849+ let missing_comment_span_lo = context
1850+ . snippet_provider
1851+ . span_after ( missing_comment_span, ":" ) ;
1852+ mk_sp ( missing_comment_span_lo, ty_span. lo ( ) )
1853+ } ;
1854+
1855+ let comment_before_colon = rewrite_missing_comment ( span_before_colon, shape, context)
1856+ . filter ( |comment| !comment. is_empty ( ) )
1857+ . map_or ( String :: new ( ) , |comment| format ! ( " {}" , comment) ) ;
1858+ let comment_after_colon = rewrite_missing_comment ( span_after_colon, shape, context)
1859+ . filter ( |comment| !comment. is_empty ( ) )
1860+ . map_or ( String :: new ( ) , |comment| format ! ( "{} " , comment) ) ;
1861+ ( comment_before_colon, comment_after_colon)
1862+ }
1863+
18311864impl Rewrite for ast:: Arg {
18321865 fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
18331866 if let Some ( ref explicit_self) = self . to_self ( ) {
@@ -1838,13 +1871,11 @@ impl Rewrite for ast::Arg {
18381871 . rewrite ( context, Shape :: legacy ( shape. width , shape. indent ) ) ?;
18391872
18401873 if !is_empty_infer ( & * self . ty , self . pat . span ) {
1841- if context. config . space_before_colon ( ) {
1842- result. push_str ( " " ) ;
1843- }
1844- result. push_str ( ":" ) ;
1845- if context. config . space_after_colon ( ) {
1846- result. push_str ( " " ) ;
1847- }
1874+ let ( before_comment, after_comment) =
1875+ get_missing_arg_comments ( context, self . pat . span , self . ty . span , shape) ;
1876+ result. push_str ( & before_comment) ;
1877+ result. push_str ( colon_spaces ( context. config ) ) ;
1878+ result. push_str ( & after_comment) ;
18481879 let overhead = last_line_width ( & result) ;
18491880 let max_width = shape. width . checked_sub ( overhead) ?;
18501881 let ty_str = self
0 commit comments