File tree Expand file tree Collapse file tree 4 files changed +43
-8
lines changed Expand file tree Collapse file tree 4 files changed +43
-8
lines changed Original file line number Diff line number Diff line change @@ -23,3 +23,6 @@ tests/cargo-fmt/**/target
23
23
.idea /
24
24
.vscode /
25
25
* ~
26
+
27
+ # Git
28
+ .git /
Original file line number Diff line number Diff line change @@ -131,14 +131,32 @@ impl Rewrite for ast::Local {
131
131
. sub_width ( 1 )
132
132
. max_width_error ( shape. width , self . span ( ) ) ?;
133
133
134
- result = rewrite_assign_rhs (
135
- context,
136
- result,
137
- init,
138
- & RhsAssignKind :: Expr ( & init. kind , init. span ) ,
139
- nested_shape,
140
- )
141
- . max_width_error ( shape. width , self . span ( ) ) ?;
134
+ let maybe_comment_span = context
135
+ . snippet_provider
136
+ . opt_span_after ( self . span , "=" )
137
+ . map ( |op_lo| mk_sp ( op_lo, init. span . lo ( ) ) ) ;
138
+
139
+ if maybe_comment_span. map_or ( true , |span| context. snippet ( span) . trim ( ) . len ( ) == 0 ) {
140
+ result = rewrite_assign_rhs (
141
+ context,
142
+ result,
143
+ init,
144
+ & RhsAssignKind :: Expr ( & init. kind , init. span ) ,
145
+ nested_shape,
146
+ )
147
+ . max_width_error ( shape. width , self . span ( ) ) ?;
148
+ } else {
149
+ result = rewrite_assign_rhs_with_comments (
150
+ context,
151
+ result,
152
+ & * init,
153
+ nested_shape,
154
+ & RhsAssignKind :: Expr ( & init. kind , init. span ) ,
155
+ RhsTactics :: Default ,
156
+ maybe_comment_span. unwrap ( ) ,
157
+ true ,
158
+ ) ?;
159
+ }
142
160
143
161
if let Some ( block) = else_block {
144
162
let else_kw_span = init. span . between ( block. span ) ;
Original file line number Diff line number Diff line change
1
+ fn main ( ) {
2
+ let foo =
3
+ // 114514
4
+ if true {
5
+ 1919
6
+ } else {
7
+ 810
8
+ } ;
9
+ }
Original file line number Diff line number Diff line change
1
+ fn main ( ) {
2
+ let foo =
3
+ // 114514
4
+ if true { 1919 } else { 810 } ;
5
+ }
You can’t perform that action at this time.
0 commit comments