@@ -26,6 +26,7 @@ use crate::utils::{last_line_width, left_most_sub_expr, stmt_expr, NodeIdExt};
26
26
27
27
pub ( crate ) fn rewrite_closure (
28
28
binder : & ast:: ClosureBinder ,
29
+ constness : ast:: Const ,
29
30
capture : ast:: CaptureBy ,
30
31
is_async : & ast:: Async ,
31
32
movability : ast:: Movability ,
@@ -38,7 +39,7 @@ pub(crate) fn rewrite_closure(
38
39
debug ! ( "rewrite_closure {:?}" , body) ;
39
40
40
41
let ( prefix, extra_offset) = rewrite_closure_fn_decl (
41
- binder, capture, is_async, movability, fn_decl, body, span, context, shape,
42
+ binder, constness , capture, is_async, movability, fn_decl, body, span, context, shape,
42
43
) ?;
43
44
// 1 = space between `|...|` and body.
44
45
let body_shape = shape. offset_left ( extra_offset) ?;
@@ -230,6 +231,7 @@ fn rewrite_closure_block(
230
231
// Return type is (prefix, extra_offset)
231
232
fn rewrite_closure_fn_decl (
232
233
binder : & ast:: ClosureBinder ,
234
+ constness : ast:: Const ,
233
235
capture : ast:: CaptureBy ,
234
236
asyncness : & ast:: Async ,
235
237
movability : ast:: Movability ,
@@ -250,6 +252,12 @@ fn rewrite_closure_fn_decl(
250
252
ast:: ClosureBinder :: NotPresent => "" . to_owned ( ) ,
251
253
} ;
252
254
255
+ let const_ = if matches ! ( constness, ast:: Const :: Yes ( _) ) {
256
+ "const "
257
+ } else {
258
+ ""
259
+ } ;
260
+
253
261
let immovable = if movability == ast:: Movability :: Static {
254
262
"static "
255
263
} else {
@@ -264,7 +272,7 @@ fn rewrite_closure_fn_decl(
264
272
// 4 = "|| {".len(), which is overconservative when the closure consists of
265
273
// a single expression.
266
274
let nested_shape = shape
267
- . shrink_left ( binder. len ( ) + immovable. len ( ) + is_async. len ( ) + mover. len ( ) ) ?
275
+ . shrink_left ( binder. len ( ) + const_ . len ( ) + immovable. len ( ) + is_async. len ( ) + mover. len ( ) ) ?
268
276
. sub_width ( 4 ) ?;
269
277
270
278
// 1 = |
@@ -302,7 +310,10 @@ fn rewrite_closure_fn_decl(
302
310
. tactic ( tactic)
303
311
. preserve_newline ( true ) ;
304
312
let list_str = write_list ( & item_vec, & fmt) ?;
305
- let mut prefix = format ! ( "{}{}{}{}|{}|" , binder, immovable, is_async, mover, list_str) ;
313
+ let mut prefix = format ! (
314
+ "{}{}{}{}{}|{}|" ,
315
+ binder, const_, immovable, is_async, mover, list_str
316
+ ) ;
306
317
307
318
if !ret_str. is_empty ( ) {
308
319
if prefix. contains ( '\n' ) {
@@ -329,6 +340,7 @@ pub(crate) fn rewrite_last_closure(
329
340
if let ast:: ExprKind :: Closure ( ref closure) = expr. kind {
330
341
let ast:: Closure {
331
342
ref binder,
343
+ constness,
332
344
capture_clause,
333
345
ref asyncness,
334
346
movability,
@@ -349,6 +361,7 @@ pub(crate) fn rewrite_last_closure(
349
361
} ;
350
362
let ( prefix, extra_offset) = rewrite_closure_fn_decl (
351
363
binder,
364
+ constness,
352
365
capture_clause,
353
366
asyncness,
354
367
movability,
0 commit comments