1
Fork 0

Rollup merge of #119444 - compiler-errors:closure-or-coroutine, r=oli-obk

Rename `TyCtxt::is_closure` to `TyCtxt::is_closure_or_coroutine`

This function has always been used to test whether the def-id was a closure **or** coroutine: https://github.com/rust-lang/rust/pull/118311/files#diff-69ebec59f7d38331dd1be84ede7957977dcaa39e30ed2869b04aa8c99b2079ccR552 -- the name is just confusing because it disagrees with other fns named `is_closure`, like `Ty::is_closure`.

So let's rename it.
This commit is contained in:
León Orell Valerian Liehr 2024-01-03 16:08:26 +01:00 committed by GitHub
commit 3053ced813
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 32 additions and 27 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,12 +661,10 @@ 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) {
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())
} else {
None
let upvars_ty = match tcx.type_of(def_id).skip_binder().kind() {
ty::Closure(..) => Some(args.as_closure().tupled_upvars_ty()),
ty::Coroutine(..) => Some(args.as_coroutine().tupled_upvars_ty()),
_ => None,
};
let has_upvars = upvars_ty.is_some_and(|ty| !ty.tuple_fields().is_empty());
debug!("polymorphize: upvars_ty={:?} has_upvars={:?}", upvars_ty, has_upvars);

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)
}