1
Fork 0

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:
Matthias Krüger 2023-10-25 23:37:11 +02:00 committed by GitHub
commit 4e4e5619af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 91 additions and 97 deletions

View file

@ -22,7 +22,7 @@ use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::Visitor;
use rustc_hir::is_range_literal;
use rustc_hir::lang_items::LangItem;
use rustc_hir::{AsyncCoroutineKind, CoroutineKind, Node};
use rustc_hir::{CoroutineKind, CoroutineSource, Node};
use rustc_hir::{Expr, HirId};
use rustc_infer::infer::error_reporting::TypeErrCtxt;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
@ -2410,7 +2410,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
.and_then(|coroutine_did| {
Some(match self.tcx.coroutine_kind(coroutine_did).unwrap() {
CoroutineKind::Coroutine => format!("coroutine is not {trait_name}"),
CoroutineKind::Async(AsyncCoroutineKind::Fn) => self
CoroutineKind::Async(CoroutineSource::Fn) => self
.tcx
.parent(coroutine_did)
.as_local()
@ -2419,10 +2419,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
.map(|name| {
format!("future returned by `{name}` is not {trait_name}")
})?,
CoroutineKind::Async(AsyncCoroutineKind::Block) => {
CoroutineKind::Async(CoroutineSource::Block) => {
format!("future created by async block is not {trait_name}")
}
CoroutineKind::Async(AsyncCoroutineKind::Closure) => {
CoroutineKind::Async(CoroutineSource::Closure) => {
format!("future created by async closure is not {trait_name}")
}
})
@ -2995,11 +2995,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let sp = self.tcx.def_span(def_id);
// Special-case this to say "async block" instead of `[static coroutine]`.
let kind = tcx.coroutine_kind(def_id).unwrap().descr();
let kind = tcx.coroutine_kind(def_id).unwrap();
err.span_note(
sp,
with_forced_trimmed_paths!(format!(
"required because it's used within this {kind}",
"required because it's used within this {kind:#}",
)),
)
}

View file

@ -1611,9 +1611,9 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
fn describe_coroutine(&self, body_id: hir::BodyId) -> Option<&'static str> {
self.tcx.hir().body(body_id).coroutine_kind.map(|gen_kind| match gen_kind {
hir::CoroutineKind::Coroutine => "a coroutine",
hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Block) => "an async block",
hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Fn) => "an async function",
hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Closure) => "an async closure",
hir::CoroutineKind::Async(hir::CoroutineSource::Block) => "an async block",
hir::CoroutineKind::Async(hir::CoroutineSource::Fn) => "an async function",
hir::CoroutineKind::Async(hir::CoroutineSource::Closure) => "an async closure",
})
}