@@ -33,6 +33,7 @@ use utils::{last_line_width, left_most_sub_expr, stmt_expr};
3333
3434pub fn rewrite_closure (
3535 capture : ast:: CaptureBy ,
36+ movability : ast:: Movability ,
3637 fn_decl : & ast:: FnDecl ,
3738 body : & ast:: Expr ,
3839 span : Span ,
@@ -42,7 +43,7 @@ pub fn rewrite_closure(
4243 debug ! ( "rewrite_closure {:?}" , body) ;
4344
4445 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) ?;
4647 // 1 = space between `|...|` and body.
4748 let body_shape = shape. offset_left ( extra_offset) ?;
4849
@@ -194,6 +195,7 @@ fn rewrite_closure_block(
194195// Return type is (prefix, extra_offset)
195196fn rewrite_closure_fn_decl (
196197 capture : ast:: CaptureBy ,
198+ movability : ast:: Movability ,
197199 fn_decl : & ast:: FnDecl ,
198200 body : & ast:: Expr ,
199201 span : Span ,
@@ -205,9 +207,17 @@ fn rewrite_closure_fn_decl(
205207 } else {
206208 ""
207209 } ;
210+
211+ let immovable = if movability == ast:: Movability :: Static {
212+ "static "
213+ } else {
214+ ""
215+ } ;
208216 // 4 = "|| {".len(), which is overconservative when the closure consists of
209217 // 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 ) ?;
211221
212222 // 1 = |
213223 let argument_offset = nested_shape. indent + 1 ;
@@ -254,7 +264,7 @@ fn rewrite_closure_fn_decl(
254264 config : context. config ,
255265 } ;
256266 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) ;
258268
259269 if !ret_str. is_empty ( ) {
260270 if prefix. contains ( '\n' ) {
@@ -278,7 +288,7 @@ pub fn rewrite_last_closure(
278288 expr : & ast:: Expr ,
279289 shape : Shape ,
280290) -> 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 {
282292 let body = match body. node {
283293 ast:: ExprKind :: Block ( ref block)
284294 if !is_unsafe_block ( block) && is_simple_block ( block, context. codemap ) =>
@@ -287,8 +297,15 @@ pub fn rewrite_last_closure(
287297 }
288298 _ => body,
289299 } ;
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+ ) ?;
292309 // If the closure goes multi line before its body, do not overflow the closure.
293310 if prefix. contains ( '\n' ) {
294311 return None ;
0 commit comments