1
Fork 0

is_coroutine -> is_coroutine_or_closure

This commit is contained in:
Michael Goulet 2023-12-30 15:19:54 +00:00
parent d59f06fc64
commit 07adee7072
15 changed files with 29 additions and 22 deletions

View file

@ -520,7 +520,7 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io:
let kind = tcx.def_kind(def_id);
let is_function = match kind {
DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) => true,
_ => tcx.is_closure(def_id),
_ => tcx.is_closure_or_coroutine(def_id),
};
match (kind, body.source.promoted) {
(_, Some(i)) => write!(w, "{i:?} in ")?,

View file

@ -197,7 +197,7 @@ pub struct ClosureTypeInfo<'tcx> {
}
fn closure_typeinfo<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> ClosureTypeInfo<'tcx> {
debug_assert!(tcx.is_closure(def.to_def_id()));
debug_assert!(tcx.is_closure_or_coroutine(def.to_def_id()));
let typeck_results = tcx.typeck(def);
let user_provided_sig = typeck_results.user_provided_sigs[&def];
let captures = typeck_results.closure_min_captures_flattened(def);
@ -217,7 +217,7 @@ impl<'tcx> TyCtxt<'tcx> {
}
pub fn closure_captures(self, def_id: LocalDefId) -> &'tcx [&'tcx ty::CapturedPlace<'tcx>] {
if !self.is_closure(def_id.to_def_id()) {
if !self.is_closure_or_coroutine(def_id.to_def_id()) {
return &[];
};
self.closure_typeinfo(def_id).captures

View file

@ -426,7 +426,10 @@ impl<'tcx> Instance<'tcx> {
) -> Option<Instance<'tcx>> {
debug!("resolve(def_id={:?}, args={:?})", def_id, args);
// Use either `resolve_closure` or `resolve_for_vtable`
assert!(!tcx.is_closure(def_id), "Called `resolve_for_fn_ptr` on closure: {def_id:?}");
assert!(
!tcx.is_closure_or_coroutine(def_id),
"Called `resolve_for_fn_ptr` on closure: {def_id:?}"
);
Instance::resolve(tcx, param_env, def_id, args).ok().flatten().map(|mut resolved| {
match resolved.def {
InstanceDef::Item(def) if resolved.def.requires_caller_location(tcx) => {
@ -488,7 +491,7 @@ impl<'tcx> Instance<'tcx> {
})
)
{
if tcx.is_closure(def) {
if tcx.is_closure_or_coroutine(def) {
debug!(" => vtable fn pointer created for closure with #[track_caller]: {:?} for method {:?} {:?}",
def, def_id, args);
@ -658,7 +661,7 @@ fn polymorphize<'tcx>(
// the unpolymorphized upvar closure would result in a polymorphized closure producing
// multiple mono items (and eventually symbol clashes).
let def_id = instance.def_id();
let upvars_ty = if tcx.is_closure(def_id) {
let upvars_ty = if tcx.is_closure_or_coroutine(def_id) {
Some(args.as_closure().tupled_upvars_ty())
} else if tcx.type_of(def_id).skip_binder().is_coroutine() {
Some(args.as_coroutine().tupled_upvars_ty())

View file

@ -547,7 +547,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// closure appears (and, sadly, a corresponding `NodeId`, since
/// those are not yet phased out). The parent of the closure's
/// `DefId` will also be the context where it appears.
pub fn is_closure(self, def_id: DefId) -> bool {
pub fn is_closure_or_coroutine(self, def_id: DefId) -> bool {
matches!(self.def_kind(def_id), DefKind::Closure)
}