File tree Expand file tree Collapse file tree 3 files changed +80
-0
lines changed Expand file tree Collapse file tree 3 files changed +80
-0
lines changed Original file line number Diff line number Diff line change @@ -2075,6 +2075,40 @@ fn rewrite_fn_base(
2075
2075
pos_before_where,
2076
2076
option,
2077
2077
) ) ;
2078
+ // If there are neither where clause nor return type, we may be missing comments between
2079
+ // args and `{`.
2080
+ if where_clause_str. is_empty ( ) {
2081
+ if let ast:: FunctionRetTy :: Default ( ret_span) = fd. output {
2082
+ let sp = mk_sp ( args_span. hi , ret_span. hi ) ;
2083
+ let missing_snippet = context. snippet ( sp) ;
2084
+ let trimmed_snippet = missing_snippet. trim ( ) ;
2085
+ let missing_comment = if trimmed_snippet. is_empty ( ) {
2086
+ String :: new ( )
2087
+ } else {
2088
+ try_opt ! ( rewrite_comment(
2089
+ trimmed_snippet,
2090
+ false ,
2091
+ Shape :: indented( indent, context. config) ,
2092
+ context. config,
2093
+ ) )
2094
+ } ;
2095
+ if !missing_comment. is_empty ( ) {
2096
+ let pos = missing_snippet. chars ( ) . position ( |c| c == '/' ) . unwrap_or ( 0 ) ;
2097
+ // 1 = ` `
2098
+ let total_width = missing_comment. len ( ) + last_line_width ( & result) + 1 ;
2099
+ let force_new_line_before_comment = missing_snippet[ ..pos] . contains ( '\n' ) ||
2100
+ total_width > context. config . max_width ( ) ;
2101
+ let sep = if force_new_line_before_comment {
2102
+ format ! ( "\n {}" , indent. to_string( context. config) )
2103
+ } else {
2104
+ String :: from ( " " )
2105
+ } ;
2106
+ result. push_str ( & sep) ;
2107
+ result. push_str ( & missing_comment) ;
2108
+ force_new_line_for_brace = true ;
2109
+ }
2110
+ }
2111
+ }
2078
2112
2079
2113
result. push_str ( & where_clause_str) ;
2080
2114
Original file line number Diff line number Diff line change @@ -59,3 +59,26 @@ fn issue_1086() {
59
59
* random comment */
60
60
61
61
fn main ( ) { /* Test */ }
62
+
63
+ // #1643
64
+ fn some_fn ( ) /* some comment */
65
+ {
66
+ }
67
+
68
+ fn some_fn1 ( )
69
+ // some comment
70
+ {
71
+ }
72
+
73
+ fn some_fn2 ( ) // some comment
74
+ {
75
+ }
76
+
77
+ fn some_fn3 ( ) /* some comment some comment some comment some comment some comment some comment so */
78
+ {
79
+ }
80
+
81
+ fn some_fn4 ( )
82
+ /* some comment some comment some comment some comment some comment some comment some comment */
83
+ {
84
+ }
Original file line number Diff line number Diff line change @@ -63,3 +63,26 @@ fn issue_1086() {
63
63
fn main ( ) {
64
64
// Test
65
65
}
66
+
67
+ // #1643
68
+ fn some_fn ( ) // some comment
69
+ {
70
+ }
71
+
72
+ fn some_fn1 ( )
73
+ // some comment
74
+ {
75
+ }
76
+
77
+ fn some_fn2 ( ) // some comment
78
+ {
79
+ }
80
+
81
+ fn some_fn3 ( ) // some comment some comment some comment some comment some comment some comment so
82
+ {
83
+ }
84
+
85
+ fn some_fn4 ( )
86
+ // some comment some comment some comment some comment some comment some comment some comment
87
+ {
88
+ }
You can’t perform that action at this time.
0 commit comments