1
Fork 0

Teach typeck/borrowck/solvers how to deal with async closures

This commit is contained in:
Michael Goulet 2024-01-24 22:27:25 +00:00
parent c567eddec2
commit a82bae2172
35 changed files with 1221 additions and 66 deletions

View file

@ -81,6 +81,7 @@ pub fn provide(providers: &mut Providers) {
impl_trait_ref,
impl_polarity,
coroutine_kind,
coroutine_for_closure,
collect_mod_item_types,
is_type_alias_impl_trait,
..*providers
@ -1531,6 +1532,36 @@ fn coroutine_kind(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<hir::CoroutineK
}
}
fn coroutine_for_closure(tcx: TyCtxt<'_>, def_id: LocalDefId) -> DefId {
let Node::Expr(&hir::Expr {
kind:
hir::ExprKind::Closure(&rustc_hir::Closure {
kind: hir::ClosureKind::CoroutineClosure(_),
body,
..
}),
..
}) = tcx.hir_node_by_def_id(def_id)
else {
bug!()
};
let &hir::Expr {
kind:
hir::ExprKind::Closure(&rustc_hir::Closure {
def_id,
kind: hir::ClosureKind::Coroutine(_),
..
}),
..
} = tcx.hir().body(body).value
else {
bug!()
};
def_id.to_def_id()
}
fn is_type_alias_impl_trait<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> bool {
match tcx.hir_node_by_def_id(def_id) {
Node::Item(hir::Item { kind: hir::ItemKind::OpaqueTy(opaque), .. }) => {