Skip to content

Commit 5c374a4

Browse files
Fix a couple more DefKind discrepancies between DefKind::Closure and DefKind::SyntheticCoroutineBody
1 parent af1ca77 commit 5c374a4

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

compiler/rustc_hir/src/def.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,10 @@ impl DefKind {
287287

288288
#[inline]
289289
pub fn is_fn_like(self) -> bool {
290-
matches!(self, DefKind::Fn | DefKind::AssocFn | DefKind::Closure)
290+
matches!(
291+
self,
292+
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::SyntheticCoroutineBody
293+
)
291294
}
292295

293296
/// Whether `query get_codegen_attrs` should be used with this definition.

compiler/rustc_mir_transform/src/cross_crate_inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
2424

2525
// This just reproduces the logic from Instance::requires_inline.
2626
match tcx.def_kind(def_id) {
27-
DefKind::Ctor(..) | DefKind::Closure => return true,
27+
DefKind::Ctor(..) | DefKind::Closure | DefKind::SyntheticCoroutineBody => return true,
2828
DefKind::Fn | DefKind::AssocFn => {}
2929
_ => return false,
3030
}

compiler/rustc_symbol_mangling/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ fn compute_symbol_name<'tcx>(
227227
// and we want to be sure to avoid any symbol conflicts here.
228228
let is_globally_shared_function = matches!(
229229
tcx.def_kind(instance.def_id()),
230-
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Ctor(..)
230+
DefKind::Fn
231+
| DefKind::AssocFn
232+
| DefKind::Closure
233+
| DefKind::SyntheticCoroutineBody
234+
| DefKind::Ctor(..)
231235
) && matches!(
232236
MonoItem::Fn(instance).instantiation_mode(tcx),
233237
InstantiationMode::GloballyShared { may_conflict: true }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//@ edition: 2021
2+
//@ compile-flags: -Zinline-mir
3+
//@ build-pass
4+
5+
// Ensure that we don't hit a Steal ICE because we forgot to ensure
6+
// `mir_inliner_callees` for the synthetic by-move coroutine body since
7+
// its def-id wasn't previously being considered.
8+
9+
#![feature(async_closure, noop_waker)]
10+
11+
use std::future::Future;
12+
use std::pin::pin;
13+
use std::task::*;
14+
15+
pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
16+
let mut fut = pin!(fut);
17+
let ctx = &mut Context::from_waker(Waker::noop());
18+
19+
loop {
20+
match fut.as_mut().poll(ctx) {
21+
Poll::Pending => {}
22+
Poll::Ready(t) => break t,
23+
}
24+
}
25+
}
26+
27+
async fn call_once<T>(f: impl async FnOnce() -> T) -> T {
28+
f().await
29+
}
30+
31+
fn main() {
32+
let c = async || {};
33+
block_on::block_on(call_once(c));
34+
}

0 commit comments

Comments
 (0)