Fix a couple more DefKind discrepancies between DefKind::Closure and DefKind::SyntheticCoroutineBody

This commit is contained in:
Michael Goulet 2024-09-16 21:40:14 -04:00
parent af1ca7794a
commit 4beb1cf9e5
4 changed files with 44 additions and 3 deletions

View File

@ -287,7 +287,10 @@ impl DefKind {
#[inline]
pub fn is_fn_like(self) -> bool {
matches!(self, DefKind::Fn | DefKind::AssocFn | DefKind::Closure)
matches!(
self,
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::SyntheticCoroutineBody
)
}
/// Whether `query get_codegen_attrs` should be used with this definition.

View File

@ -24,7 +24,7 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
// This just reproduces the logic from Instance::requires_inline.
match tcx.def_kind(def_id) {
DefKind::Ctor(..) | DefKind::Closure => return true,
DefKind::Ctor(..) | DefKind::Closure | DefKind::SyntheticCoroutineBody => return true,
DefKind::Fn | DefKind::AssocFn => {}
_ => return false,
}

View File

@ -227,7 +227,11 @@ fn compute_symbol_name<'tcx>(
// and we want to be sure to avoid any symbol conflicts here.
let is_globally_shared_function = matches!(
tcx.def_kind(instance.def_id()),
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Ctor(..)
DefKind::Fn
| DefKind::AssocFn
| DefKind::Closure
| DefKind::SyntheticCoroutineBody
| DefKind::Ctor(..)
) && matches!(
MonoItem::Fn(instance).instantiation_mode(tcx),
InstantiationMode::GloballyShared { may_conflict: true }

View File

@ -0,0 +1,34 @@
//@ edition: 2021
//@ compile-flags: -Zinline-mir
//@ build-pass
// Ensure that we don't hit a Steal ICE because we forgot to ensure
// `mir_inliner_callees` for the synthetic by-move coroutine body since
// its def-id wasn't previously being considered.
#![feature(async_closure, noop_waker)]
use std::future::Future;
use std::pin::pin;
use std::task::*;
pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
let mut fut = pin!(fut);
let ctx = &mut Context::from_waker(Waker::noop());
loop {
match fut.as_mut().poll(ctx) {
Poll::Pending => {}
Poll::Ready(t) => break t,
}
}
}
async fn call_once<T>(f: impl async FnOnce() -> T) -> T {
f().await
}
fn main() {
let c = async || {};
block_on(call_once(c));
}