Skip to content

Commit ea4cbff

Browse files
committed
Encode optimized MIR of generators when emitting metadata
1 parent c7b0ddb commit ea4cbff

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,10 @@ impl EncodeContext<'a, 'tcx> {
15071507
record!(self.tables.fn_sig[def_id] <- substs.as_closure().sig());
15081508
}
15091509
self.encode_generics(def_id.to_def_id());
1510-
let opt_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir || self.emit_codegen_mir;
1510+
let opt_mir = // FIXME: Optimized MIR is necessary to determine the layout of generators.
1511+
matches!(ty.kind(), ty::Generator(..))
1512+
|| self.tcx.sess.opts.debugging_opts.always_encode_mir
1513+
|| self.emit_codegen_mir;
15111514
if opt_mir {
15121515
self.encode_optimized_mir(def_id);
15131516
self.encode_promoted_mir(def_id);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// compile-flags: --emit metadata
2+
#![feature(generators, generator_trait)]
3+
4+
use std::marker::Unpin;
5+
use std::ops::Generator;
6+
7+
pub fn g() -> impl Generator<(), Yield = (), Return = ()> {
8+
|| {
9+
yield;
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Check that the layout of a generator is available when auxiliary crate
2+
// is compiled with --emit metadata.
3+
//
4+
// Regression test for #80998.
5+
//
6+
// aux-build:metadata-sufficient-for-layout.rs
7+
// check-pass
8+
9+
#![feature(type_alias_impl_trait)]
10+
#![feature(generator_trait)]
11+
12+
extern crate metadata_sufficient_for_layout;
13+
14+
use std::ops::Generator;
15+
16+
type F = impl Generator<(), Yield = (), Return = ()>;
17+
18+
// Static queries the layout of the generator.
19+
static A: Option<F> = None;
20+
21+
fn f() -> F { metadata_sufficient_for_layout::g() }
22+
23+
fn main() {}

0 commit comments

Comments
 (0)