@@ -29,7 +29,7 @@ pub(crate) fn rewrite_closure(
2929 binder : & ast:: ClosureBinder ,
3030 constness : ast:: Const ,
3131 capture : ast:: CaptureBy ,
32- is_async : & ast:: Async ,
32+ coroutine_kind : & Option < ast:: CoroutineKind > ,
3333 movability : ast:: Movability ,
3434 fn_decl : & ast:: FnDecl ,
3535 body : & ast:: Expr ,
@@ -40,7 +40,16 @@ pub(crate) fn rewrite_closure(
4040 debug ! ( "rewrite_closure {:?}" , body) ;
4141
4242 let ( prefix, extra_offset) = rewrite_closure_fn_decl (
43- binder, constness, capture, is_async, movability, fn_decl, body, span, context, shape,
43+ binder,
44+ constness,
45+ capture,
46+ coroutine_kind,
47+ movability,
48+ fn_decl,
49+ body,
50+ span,
51+ context,
52+ shape,
4453 ) ?;
4554 // 1 = space between `|...|` and body.
4655 let body_shape = shape. offset_left ( extra_offset) ?;
@@ -188,7 +197,7 @@ fn rewrite_closure_expr(
188197 fn allow_multi_line ( expr : & ast:: Expr ) -> bool {
189198 match expr. kind {
190199 ast:: ExprKind :: Match ( ..)
191- | ast:: ExprKind :: Async ( ..)
200+ | ast:: ExprKind :: Gen ( ..)
192201 | ast:: ExprKind :: Block ( ..)
193202 | ast:: ExprKind :: TryBlock ( ..)
194203 | ast:: ExprKind :: Loop ( ..)
@@ -233,7 +242,7 @@ fn rewrite_closure_fn_decl(
233242 binder : & ast:: ClosureBinder ,
234243 constness : ast:: Const ,
235244 capture : ast:: CaptureBy ,
236- asyncness : & ast:: Async ,
245+ coroutine_kind : & Option < ast:: CoroutineKind > ,
237246 movability : ast:: Movability ,
238247 fn_decl : & ast:: FnDecl ,
239248 body : & ast:: Expr ,
@@ -263,16 +272,21 @@ fn rewrite_closure_fn_decl(
263272 } else {
264273 ""
265274 } ;
266- let is_async = if asyncness. is_async ( ) { "async " } else { "" } ;
267- let mover = if capture == ast:: CaptureBy :: Value {
275+ let coro = match coroutine_kind {
276+ Some ( ast:: CoroutineKind :: Async { .. } ) => "async " ,
277+ Some ( ast:: CoroutineKind :: Gen { .. } ) => "gen " ,
278+ Some ( ast:: CoroutineKind :: AsyncGen { .. } ) => "async gen " ,
279+ None => "" ,
280+ } ;
281+ let mover = if matches ! ( capture, ast:: CaptureBy :: Value { .. } ) {
268282 "move "
269283 } else {
270284 ""
271285 } ;
272286 // 4 = "|| {".len(), which is overconservative when the closure consists of
273287 // a single expression.
274288 let nested_shape = shape
275- . shrink_left ( binder. len ( ) + const_. len ( ) + immovable. len ( ) + is_async . len ( ) + mover. len ( ) ) ?
289+ . shrink_left ( binder. len ( ) + const_. len ( ) + immovable. len ( ) + coro . len ( ) + mover. len ( ) ) ?
276290 . sub_width ( 4 ) ?;
277291
278292 // 1 = |
@@ -310,7 +324,7 @@ fn rewrite_closure_fn_decl(
310324 . tactic ( tactic)
311325 . preserve_newline ( true ) ;
312326 let list_str = write_list ( & item_vec, & fmt) ?;
313- let mut prefix = format ! ( "{binder}{const_}{immovable}{is_async }{mover}|{list_str}|" ) ;
327+ let mut prefix = format ! ( "{binder}{const_}{immovable}{coro }{mover}|{list_str}|" ) ;
314328
315329 if !ret_str. is_empty ( ) {
316330 if prefix. contains ( '\n' ) {
@@ -339,7 +353,7 @@ pub(crate) fn rewrite_last_closure(
339353 ref binder,
340354 constness,
341355 capture_clause,
342- ref asyncness ,
356+ ref coroutine_kind ,
343357 movability,
344358 ref fn_decl,
345359 ref body,
@@ -360,7 +374,7 @@ pub(crate) fn rewrite_last_closure(
360374 binder,
361375 constness,
362376 capture_clause,
363- asyncness ,
377+ coroutine_kind ,
364378 movability,
365379 fn_decl,
366380 body,
0 commit comments