@@ -33,6 +33,7 @@ use utils::{last_line_width, left_most_sub_expr, stmt_expr};
33
33
34
34
pub fn rewrite_closure (
35
35
capture : ast:: CaptureBy ,
36
+ movability : ast:: Movability ,
36
37
fn_decl : & ast:: FnDecl ,
37
38
body : & ast:: Expr ,
38
39
span : Span ,
@@ -42,7 +43,7 @@ pub fn rewrite_closure(
42
43
debug ! ( "rewrite_closure {:?}" , body) ;
43
44
44
45
let ( prefix, extra_offset) =
45
- rewrite_closure_fn_decl ( capture, fn_decl, body, span, context, shape) ?;
46
+ rewrite_closure_fn_decl ( capture, movability , fn_decl, body, span, context, shape) ?;
46
47
// 1 = space between `|...|` and body.
47
48
let body_shape = shape. offset_left ( extra_offset) ?;
48
49
@@ -194,6 +195,7 @@ fn rewrite_closure_block(
194
195
// Return type is (prefix, extra_offset)
195
196
fn rewrite_closure_fn_decl (
196
197
capture : ast:: CaptureBy ,
198
+ movability : ast:: Movability ,
197
199
fn_decl : & ast:: FnDecl ,
198
200
body : & ast:: Expr ,
199
201
span : Span ,
@@ -205,9 +207,17 @@ fn rewrite_closure_fn_decl(
205
207
} else {
206
208
""
207
209
} ;
210
+
211
+ let immovable = if movability == ast:: Movability :: Static {
212
+ "static "
213
+ } else {
214
+ ""
215
+ } ;
208
216
// 4 = "|| {".len(), which is overconservative when the closure consists of
209
217
// a single expression.
210
- let nested_shape = shape. shrink_left ( mover. len ( ) ) ?. sub_width ( 4 ) ?;
218
+ let nested_shape = shape
219
+ . shrink_left ( mover. len ( ) + immovable. len ( ) ) ?
220
+ . sub_width ( 4 ) ?;
211
221
212
222
// 1 = |
213
223
let argument_offset = nested_shape. indent + 1 ;
@@ -254,7 +264,7 @@ fn rewrite_closure_fn_decl(
254
264
config : context. config ,
255
265
} ;
256
266
let list_str = write_list ( & item_vec, & fmt) ?;
257
- let mut prefix = format ! ( "{}|{}|" , mover, list_str) ;
267
+ let mut prefix = format ! ( "{}{} |{}|" , immovable , mover, list_str) ;
258
268
259
269
if !ret_str. is_empty ( ) {
260
270
if prefix. contains ( '\n' ) {
@@ -278,7 +288,7 @@ pub fn rewrite_last_closure(
278
288
expr : & ast:: Expr ,
279
289
shape : Shape ,
280
290
) -> Option < String > {
281
- if let ast:: ExprKind :: Closure ( capture, _ , ref fn_decl, ref body, _) = expr. node {
291
+ if let ast:: ExprKind :: Closure ( capture, movability , ref fn_decl, ref body, _) = expr. node {
282
292
let body = match body. node {
283
293
ast:: ExprKind :: Block ( ref block)
284
294
if !is_unsafe_block ( block) && is_simple_block ( block, context. codemap ) =>
@@ -287,8 +297,15 @@ pub fn rewrite_last_closure(
287
297
}
288
298
_ => body,
289
299
} ;
290
- let ( prefix, extra_offset) =
291
- rewrite_closure_fn_decl ( capture, fn_decl, body, expr. span , context, shape) ?;
300
+ let ( prefix, extra_offset) = rewrite_closure_fn_decl (
301
+ capture,
302
+ movability,
303
+ fn_decl,
304
+ body,
305
+ expr. span ,
306
+ context,
307
+ shape,
308
+ ) ?;
292
309
// If the closure goes multi line before its body, do not overflow the closure.
293
310
if prefix. contains ( '\n' ) {
294
311
return None ;
0 commit comments