Rollup merge of #117175 - oli-obk:gen_fn_split, r=compiler-errors
Rename AsyncCoroutineKind to CoroutineSource pulled out of https://github.com/rust-lang/rust/pull/116447 Also refactors the printing infra of `CoroutineSource` to be ready for easily extending it with a `Gen` variant for `gen` blocks
This commit is contained in:
commit
4e4e5619af
27 changed files with 91 additions and 97 deletions
|
@ -1511,7 +1511,7 @@ impl<'hir> Body<'hir> {
|
|||
#[derive(HashStable_Generic, Encodable, Decodable)]
|
||||
pub enum CoroutineKind {
|
||||
/// An explicit `async` block or the body of an async function.
|
||||
Async(AsyncCoroutineKind),
|
||||
Async(CoroutineSource),
|
||||
|
||||
/// A coroutine literal created via a `yield` inside a closure.
|
||||
Coroutine,
|
||||
|
@ -1520,56 +1520,45 @@ pub enum CoroutineKind {
|
|||
impl fmt::Display for CoroutineKind {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
CoroutineKind::Async(k) => fmt::Display::fmt(k, f),
|
||||
CoroutineKind::Async(k) => {
|
||||
if f.alternate() {
|
||||
f.write_str("`async` ")?;
|
||||
} else {
|
||||
f.write_str("async ")?
|
||||
}
|
||||
k.fmt(f)
|
||||
}
|
||||
CoroutineKind::Coroutine => f.write_str("coroutine"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CoroutineKind {
|
||||
pub fn descr(&self) -> &'static str {
|
||||
match self {
|
||||
CoroutineKind::Async(ask) => ask.descr(),
|
||||
CoroutineKind::Coroutine => "coroutine",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// In the case of a coroutine created as part of an async construct,
|
||||
/// which kind of async construct caused it to be created?
|
||||
/// In the case of a coroutine created as part of an async/gen construct,
|
||||
/// which kind of async/gen construct caused it to be created?
|
||||
///
|
||||
/// This helps error messages but is also used to drive coercions in
|
||||
/// type-checking (see #60424).
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug, Copy)]
|
||||
#[derive(HashStable_Generic, Encodable, Decodable)]
|
||||
pub enum AsyncCoroutineKind {
|
||||
/// An explicit `async` block written by the user.
|
||||
pub enum CoroutineSource {
|
||||
/// An explicit `async`/`gen` block written by the user.
|
||||
Block,
|
||||
|
||||
/// An explicit `async` closure written by the user.
|
||||
/// An explicit `async`/`gen` closure written by the user.
|
||||
Closure,
|
||||
|
||||
/// The `async` block generated as the body of an async function.
|
||||
/// The `async`/`gen` block generated as the body of an async/gen function.
|
||||
Fn,
|
||||
}
|
||||
|
||||
impl fmt::Display for AsyncCoroutineKind {
|
||||
impl fmt::Display for CoroutineSource {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(match self {
|
||||
AsyncCoroutineKind::Block => "async block",
|
||||
AsyncCoroutineKind::Closure => "async closure body",
|
||||
AsyncCoroutineKind::Fn => "async fn body",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl AsyncCoroutineKind {
|
||||
pub fn descr(&self) -> &'static str {
|
||||
match self {
|
||||
AsyncCoroutineKind::Block => "`async` block",
|
||||
AsyncCoroutineKind::Closure => "`async` closure body",
|
||||
AsyncCoroutineKind::Fn => "`async fn` body",
|
||||
CoroutineSource::Block => "block",
|
||||
CoroutineSource::Closure => "closure body",
|
||||
CoroutineSource::Fn => "fn body",
|
||||
}
|
||||
.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue