Skip to content

Commit 780fd74

Browse files
authored
Rollup merge of #139193 - compiler-errors:inline-synthetic, r=eholk
Feed HIR for by-move coroutine body def, since the inliner tries to read its attrs See the comments in the test. I'm surprised that nobody found this[^1] (edit: nvm haha), but you have to go out of your way to construct the by-move body and then inline it w/ a poll call, so I guess the inliner just never really gets into this situation before. Fixes #134335 r? oli-obk [^1]: Well, ``@eholk`` found this when working on the `iter! {}` macro, since it more dramatically affects those.
2 parents 40a9ccc + e2d5033 commit 780fd74

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

compiler/rustc_mir_transform/src/coroutine/by_move_body.rs

+2
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ pub(crate) fn coroutine_by_move_body_def_id<'tcx>(
219219
mir::MirSource::from_instance(InstanceKind::Item(body_def.def_id().to_def_id()));
220220
dump_mir(tcx, false, "built", &"after", &by_move_body, |_, _| Ok(()));
221221

222+
// Feed HIR because we try to access this body's attrs in the inliner.
223+
body_def.feed_hir();
222224
// Inherited from the by-ref coroutine.
223225
body_def.codegen_fn_attrs(tcx.codegen_fn_attrs(coroutine_def_id).clone());
224226
body_def.coverage_attr_on(tcx.coverage_attr_on(coroutine_def_id));

tests/crashes/134335.rs

-12
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//@ check-pass
2+
//@ compile-flags: -Zinline-mir -Zvalidate-mir
3+
//@ edition: 2024
4+
5+
// See comment below.
6+
7+
use std::future::Future;
8+
use std::pin::pin;
9+
use std::task::{Context, Waker};
10+
11+
fn call_once<T>(f: impl FnOnce() -> T) -> T { f() }
12+
13+
fn main() {
14+
let x = async || {};
15+
// We first inline `call_once<{async closure}>`.
16+
//
17+
// This gives us a future whose type is the "FnOnce" flavor of the async closure's
18+
// child coroutine. The body of this coroutine is synthetic, which we synthesize in
19+
// the by-move body query.
20+
let fut = pin!(call_once(x));
21+
// We then try to inline that body in this poll call.
22+
//
23+
// The inliner does some inlinability checks; one of these checks involves checking
24+
// the body for the `#[rustc_no_mir_inline]` attribute. Since the synthetic body had
25+
// no HIR synthesized, but it's still a local def id, we end up ICEing in the
26+
// `local_def_id_to_hir_id` call when trying to read its attrs.
27+
fut.poll(&mut Context::from_waker(Waker::noop()));
28+
}

0 commit comments

Comments
 (0)