summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_hir_typeck/src/check.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /compiler/rustc_hir_typeck/src/check.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_hir_typeck/src/check.rs')
-rw-r--r--compiler/rustc_hir_typeck/src/check.rs61
1 files changed, 37 insertions, 24 deletions
diff --git a/compiler/rustc_hir_typeck/src/check.rs b/compiler/rustc_hir_typeck/src/check.rs
index 1fa0ec173..b8a265d49 100644
--- a/compiler/rustc_hir_typeck/src/check.rs
+++ b/compiler/rustc_hir_typeck/src/check.rs
@@ -2,8 +2,8 @@ use std::cell::RefCell;
use crate::coercion::CoerceMany;
use crate::gather_locals::GatherLocalsVisitor;
+use crate::CoroutineTypes;
use crate::FnCtxt;
-use crate::GeneratorTypes;
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::intravisit::Visitor;
@@ -31,9 +31,9 @@ pub(super) fn check_fn<'a, 'tcx>(
decl: &'tcx hir::FnDecl<'tcx>,
fn_def_id: LocalDefId,
body: &'tcx hir::Body<'tcx>,
- can_be_generator: Option<hir::Movability>,
+ can_be_coroutine: Option<hir::Movability>,
params_can_be_unsized: bool,
-) -> Option<GeneratorTypes<'tcx>> {
+) -> Option<CoroutineTypes<'tcx>> {
let fn_id = fcx.tcx.hir().local_def_id_to_hir_id(fn_def_id);
let tcx = fcx.tcx;
@@ -55,18 +55,23 @@ pub(super) fn check_fn<'a, 'tcx>(
fn_maybe_err(tcx, span, fn_sig.abi);
- if let Some(kind) = body.generator_kind && can_be_generator.is_some() {
- let yield_ty = if kind == hir::GeneratorKind::Gen {
- let yield_ty = fcx
- .next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span });
- fcx.require_type_is_sized(yield_ty, span, traits::SizedYieldType);
- yield_ty
- } else {
- Ty::new_unit(tcx,)
+ if let Some(kind) = body.coroutine_kind
+ && can_be_coroutine.is_some()
+ {
+ let yield_ty = match kind {
+ hir::CoroutineKind::Gen(..) | hir::CoroutineKind::Coroutine => {
+ let yield_ty = fcx.next_ty_var(TypeVariableOrigin {
+ kind: TypeVariableOriginKind::TypeInference,
+ span,
+ });
+ fcx.require_type_is_sized(yield_ty, span, traits::SizedYieldType);
+ yield_ty
+ }
+ hir::CoroutineKind::Async(..) => Ty::new_unit(tcx),
};
- // Resume type defaults to `()` if the generator has no argument.
- let resume_ty = fn_sig.inputs().get(0).copied().unwrap_or_else(|| Ty::new_unit(tcx,));
+ // Resume type defaults to `()` if the coroutine has no argument.
+ let resume_ty = fn_sig.inputs().get(0).copied().unwrap_or_else(|| Ty::new_unit(tcx));
fcx.resume_yield_tys = Some((resume_ty, yield_ty));
}
@@ -113,28 +118,34 @@ pub(super) fn check_fn<'a, 'tcx>(
fcx.typeck_results.borrow_mut().liberated_fn_sigs_mut().insert(fn_id, fn_sig);
- fcx.require_type_is_sized(declared_ret_ty, decl.output.span(), traits::SizedReturnType);
+ let return_or_body_span = match decl.output {
+ hir::FnRetTy::DefaultReturn(_) => body.value.span,
+ hir::FnRetTy::Return(ty) => ty.span,
+ };
+ fcx.require_type_is_sized(declared_ret_ty, return_or_body_span, traits::SizedReturnType);
fcx.check_return_expr(&body.value, false);
- // We insert the deferred_generator_interiors entry after visiting the body.
- // This ensures that all nested generators appear before the entry of this generator.
- // resolve_generator_interiors relies on this property.
- let gen_ty = if let (Some(_), Some(gen_kind)) = (can_be_generator, body.generator_kind) {
+ // We insert the deferred_coroutine_interiors entry after visiting the body.
+ // This ensures that all nested coroutines appear before the entry of this coroutine.
+ // resolve_coroutine_interiors relies on this property.
+ let coroutine_ty = if let (Some(_), Some(coroutine_kind)) =
+ (can_be_coroutine, body.coroutine_kind)
+ {
let interior = fcx
.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::MiscVariable, span });
- fcx.deferred_generator_interiors.borrow_mut().push((
+ fcx.deferred_coroutine_interiors.borrow_mut().push((
fn_def_id,
body.id(),
interior,
- gen_kind,
+ coroutine_kind,
));
let (resume_ty, yield_ty) = fcx.resume_yield_tys.unwrap();
- Some(GeneratorTypes {
+ Some(CoroutineTypes {
resume_ty,
yield_ty,
interior,
- movability: can_be_generator.unwrap(),
+ movability: can_be_coroutine.unwrap(),
})
} else {
None
@@ -169,11 +180,13 @@ pub(super) fn check_fn<'a, 'tcx>(
check_panic_info_fn(tcx, panic_impl_did.expect_local(), fn_sig);
}
- if let Some(lang_start_defid) = tcx.lang_items().start_fn() && lang_start_defid == fn_def_id.to_def_id() {
+ if let Some(lang_start_defid) = tcx.lang_items().start_fn()
+ && lang_start_defid == fn_def_id.to_def_id()
+ {
check_lang_start_fn(tcx, fn_sig, fn_def_id);
}
- gen_ty
+ coroutine_ty
}
fn check_panic_info_fn(tcx: TyCtxt<'_>, fn_id: LocalDefId, fn_sig: ty::FnSig<'_>) {