Fix a couple more DefKind discrepancies between DefKind::Closure and DefKind::SyntheticCoroutineBody
This commit is contained in:
parent
af1ca7794a
commit
4beb1cf9e5
4 changed files with 44 additions and 3 deletions
|
@ -287,7 +287,10 @@ impl DefKind {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_fn_like(self) -> bool {
|
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.
|
/// Whether `query get_codegen_attrs` should be used with this definition.
|
||||||
|
|
|
@ -24,7 +24,7 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||||
|
|
||||||
// This just reproduces the logic from Instance::requires_inline.
|
// This just reproduces the logic from Instance::requires_inline.
|
||||||
match tcx.def_kind(def_id) {
|
match tcx.def_kind(def_id) {
|
||||||
DefKind::Ctor(..) | DefKind::Closure => return true,
|
DefKind::Ctor(..) | DefKind::Closure | DefKind::SyntheticCoroutineBody => return true,
|
||||||
DefKind::Fn | DefKind::AssocFn => {}
|
DefKind::Fn | DefKind::AssocFn => {}
|
||||||
_ => return false,
|
_ => return false,
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,7 +227,11 @@ fn compute_symbol_name<'tcx>(
|
||||||
// and we want to be sure to avoid any symbol conflicts here.
|
// and we want to be sure to avoid any symbol conflicts here.
|
||||||
let is_globally_shared_function = matches!(
|
let is_globally_shared_function = matches!(
|
||||||
tcx.def_kind(instance.def_id()),
|
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!(
|
) && matches!(
|
||||||
MonoItem::Fn(instance).instantiation_mode(tcx),
|
MonoItem::Fn(instance).instantiation_mode(tcx),
|
||||||
InstantiationMode::GloballyShared { may_conflict: true }
|
InstantiationMode::GloballyShared { may_conflict: true }
|
||||||
|
|
34
tests/ui/async-await/async-closures/inline-body.rs
Normal file
34
tests/ui/async-await/async-closures/inline-body.rs
Normal 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));
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue