@@ -1511,7 +1511,7 @@ impl<'hir> Body<'hir> {
15111511#[ derive( HashStable_Generic , Encodable , Decodable ) ]
15121512pub enum CoroutineKind {
15131513 /// An explicit `async` block or the body of an async function.
1514- Async ( AsyncCoroutineKind ) ,
1514+ Async ( CoroutineSource ) ,
15151515
15161516 /// A coroutine literal created via a `yield` inside a closure.
15171517 Coroutine ,
@@ -1520,56 +1520,45 @@ pub enum CoroutineKind {
15201520impl fmt:: Display for CoroutineKind {
15211521 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
15221522 match self {
1523- CoroutineKind :: Async ( k) => fmt:: Display :: fmt ( k, f) ,
1523+ CoroutineKind :: Async ( k) => {
1524+ if f. alternate ( ) {
1525+ f. write_str ( "`async` " ) ?;
1526+ } else {
1527+ f. write_str ( "async " ) ?
1528+ }
1529+ k. fmt ( f)
1530+ }
15241531 CoroutineKind :: Coroutine => f. write_str ( "coroutine" ) ,
15251532 }
15261533 }
15271534}
15281535
1529- impl CoroutineKind {
1530- pub fn descr ( & self ) -> & ' static str {
1531- match self {
1532- CoroutineKind :: Async ( ask) => ask. descr ( ) ,
1533- CoroutineKind :: Coroutine => "coroutine" ,
1534- }
1535- }
1536- }
1537-
1538- /// In the case of a coroutine created as part of an async construct,
1539- /// which kind of async construct caused it to be created?
1536+ /// In the case of a coroutine created as part of an async/gen construct,
1537+ /// which kind of async/gen construct caused it to be created?
15401538///
15411539/// This helps error messages but is also used to drive coercions in
15421540/// type-checking (see #60424).
15431541#[ derive( Clone , PartialEq , Eq , Hash , Debug , Copy ) ]
15441542#[ derive( HashStable_Generic , Encodable , Decodable ) ]
1545- pub enum AsyncCoroutineKind {
1546- /// An explicit `async` block written by the user.
1543+ pub enum CoroutineSource {
1544+ /// An explicit `async`/`gen` block written by the user.
15471545 Block ,
15481546
1549- /// An explicit `async` closure written by the user.
1547+ /// An explicit `async`/`gen` closure written by the user.
15501548 Closure ,
15511549
1552- /// The `async` block generated as the body of an async function.
1550+ /// The `async`/`gen` block generated as the body of an async/gen function.
15531551 Fn ,
15541552}
15551553
1556- impl fmt:: Display for AsyncCoroutineKind {
1554+ impl fmt:: Display for CoroutineSource {
15571555 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1558- f. write_str ( match self {
1559- AsyncCoroutineKind :: Block => "async block" ,
1560- AsyncCoroutineKind :: Closure => "async closure body" ,
1561- AsyncCoroutineKind :: Fn => "async fn body" ,
1562- } )
1563- }
1564- }
1565-
1566- impl AsyncCoroutineKind {
1567- pub fn descr ( & self ) -> & ' static str {
15681556 match self {
1569- AsyncCoroutineKind :: Block => "`async` block" ,
1570- AsyncCoroutineKind :: Closure => "`async` closure body" ,
1571- AsyncCoroutineKind :: Fn => "`async fn` body" ,
1557+ CoroutineSource :: Block => "block" ,
1558+ CoroutineSource :: Closure => "closure body" ,
1559+ CoroutineSource :: Fn => "fn body" ,
15721560 }
1561+ . fmt ( f)
15731562 }
15741563}
15751564
0 commit comments