@@ -36,7 +36,7 @@ const DEFAULT_VISIBILITY: ast::Visibility = source_map::Spanned {
36
36
} ;
37
37
38
38
fn type_annotation_separator ( config : & Config ) -> & str {
39
- colon_spaces ( config. space_before_colon ( ) , config . space_after_colon ( ) )
39
+ colon_spaces ( config)
40
40
}
41
41
42
42
// Statements of the form
@@ -1695,10 +1695,7 @@ fn rewrite_static(
1695
1695
static_parts : & StaticParts < ' _ > ,
1696
1696
offset : Indent ,
1697
1697
) -> 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 ) ;
1702
1699
let mut prefix = format ! (
1703
1700
"{}{}{} {}{}{}" ,
1704
1701
format_visibility( context, static_parts. vis) ,
@@ -1828,6 +1825,42 @@ fn is_empty_infer(ty: &ast::Ty, pat_span: Span) -> bool {
1828
1825
}
1829
1826
}
1830
1827
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
+
1831
1864
impl Rewrite for ast:: Arg {
1832
1865
fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
1833
1866
if let Some ( ref explicit_self) = self . to_self ( ) {
@@ -1838,13 +1871,11 @@ impl Rewrite for ast::Arg {
1838
1871
. rewrite ( context, Shape :: legacy ( shape. width , shape. indent ) ) ?;
1839
1872
1840
1873
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) ;
1848
1879
let overhead = last_line_width ( & result) ;
1849
1880
let max_width = shape. width . checked_sub ( overhead) ?;
1850
1881
let ty_str = self
0 commit comments