Skip to content

Commit 5e31cd3

Browse files
Support opaque_types_defined_by for SyntheticCoroutineBody
1 parent 95a2212 commit 5e31cd3

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

compiler/rustc_ty_utils/src/opaque_types.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,10 @@ fn opaque_types_defined_by<'tcx>(
321321
collector.collect_taits_declared_in_body();
322322
}
323323
// Closures and coroutines are type checked with their parent
324-
DefKind::Closure | DefKind::InlineConst => {
324+
// Note that we also support `SyntheticCoroutineBody` since we create
325+
// a MIR body for the def kind, and some MIR passes (like promotion)
326+
// may require doing analysis using its typing env.
327+
DefKind::Closure | DefKind::InlineConst | DefKind::SyntheticCoroutineBody => {
325328
collector.opaques.extend(tcx.opaque_types_defined_by(tcx.local_parent(item)));
326329
}
327330
DefKind::AssocTy | DefKind::TyAlias | DefKind::GlobalAsm => {}
@@ -343,8 +346,7 @@ fn opaque_types_defined_by<'tcx>(
343346
| DefKind::ForeignMod
344347
| DefKind::Field
345348
| DefKind::LifetimeParam
346-
| DefKind::Impl { .. }
347-
| DefKind::SyntheticCoroutineBody => {
349+
| DefKind::Impl { .. } => {
348350
span_bug!(
349351
tcx.def_span(item),
350352
"`opaque_types_defined_by` not defined for {} `{item:?}`",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ build-pass
2+
//@ compile-flags: --crate-type=lib
3+
//@ edition: 2024
4+
5+
union U {
6+
f: i32,
7+
}
8+
9+
fn foo() {
10+
async || {
11+
&U { f: 1 }
12+
};
13+
}

0 commit comments

Comments
 (0)