Skip to content

Commit

Permalink
Fix a couple more DefKind discrepancies between DefKind::Closure and …
Browse files Browse the repository at this point in the history
…DefKind::SyntheticCoroutineBody
  • Loading branch information
compiler-errors committed Sep 17, 2024
1 parent af1ca77 commit 5c374a4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
5 changes: 4 additions & 1 deletion compiler/rustc_hir/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/cross_crate_inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_symbol_mangling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
34 changes: 34 additions & 0 deletions tests/ui/async-await/async-closures/inline-body.rs
Original file line number Diff line number Diff line change
@@ -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::block_on(call_once(c));
}

0 comments on commit 5c374a4

Please sign in to comment.