Skip to content

Commit 71d4523

Browse files
Normalize closure instance before eagerly monomorphizing it
1 parent a567209 commit 71d4523

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,13 @@ impl<'v> RootCollector<'_, 'v> {
15091509
}
15101510
_ => unreachable!(),
15111511
};
1512+
let Ok(instance) = self.tcx.try_normalize_erasing_regions(
1513+
ty::TypingEnv::fully_monomorphized(),
1514+
instance,
1515+
) else {
1516+
// Don't ICE on an impossible-to-normalize closure.
1517+
return;
1518+
};
15121519
let mono_item = create_fn_mono_item(self.tcx, instance, DUMMY_SP);
15131520
if mono_item.node.is_instantiable(self.tcx) {
15141521
self.output.push(mono_item);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ compile-flags: -Zprint-mono-items=eager -Csymbol-mangling-version=v0
2+
//@ build-pass
3+
4+
// Ensure that when eagerly collecting `test::{closure#0}`, we don't try
5+
// collecting an unnormalized version of the closure (specifically its
6+
// upvars), since the closure captures the RPIT `opaque::{opaque#0}`.
7+
8+
fn opaque() -> impl Sized {}
9+
10+
fn test() -> impl FnOnce() {
11+
let opaque = opaque();
12+
move || {
13+
let opaque = opaque;
14+
}
15+
}
16+
17+
fn main() {
18+
test()();
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
MONO_ITEM fn <() as std::process::Termination>::report @@ eager_mono_with_normalizable_upvars.b15aab124d22de9b-cgu.0[Internal]
2+
MONO_ITEM fn <fn() as std::ops::FnOnce<()>>::call_once - shim(fn()) @@ eager_mono_with_normalizable_upvars.b15aab124d22de9b-cgu.0[Internal]
3+
MONO_ITEM fn <{closure@std::rt::lang_start<()>::{closure#0}} as std::ops::FnOnce<()>>::call_once - shim @@ eager_mono_with_normalizable_upvars.b15aab124d22de9b-cgu.0[Internal]
4+
MONO_ITEM fn <{closure@std::rt::lang_start<()>::{closure#0}} as std::ops::FnOnce<()>>::call_once - shim(vtable) @@ eager_mono_with_normalizable_upvars.b15aab124d22de9b-cgu.0[Internal]
5+
MONO_ITEM fn main @@ eager_mono_with_normalizable_upvars.b15aab124d22de9b-cgu.0[Internal]
6+
MONO_ITEM fn opaque @@ eager_mono_with_normalizable_upvars.b15aab124d22de9b-cgu.0[Internal]
7+
MONO_ITEM fn std::ptr::drop_in_place::<{closure@std::rt::lang_start<()>::{closure#0}}> - shim(None) @@ eager_mono_with_normalizable_upvars.b15aab124d22de9b-cgu.0[Internal]
8+
MONO_ITEM fn std::rt::lang_start::<()> @@ eager_mono_with_normalizable_upvars.b15aab124d22de9b-cgu.0[External]
9+
MONO_ITEM fn std::rt::lang_start::<()>::{closure#0} @@ eager_mono_with_normalizable_upvars.b15aab124d22de9b-cgu.0[Internal]
10+
MONO_ITEM fn std::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()> @@ eager_mono_with_normalizable_upvars.b15aab124d22de9b-cgu.0[Internal]
11+
MONO_ITEM fn test @@ eager_mono_with_normalizable_upvars.b15aab124d22de9b-cgu.0[Internal]
12+
MONO_ITEM fn test::{closure#0} @@ eager_mono_with_normalizable_upvars.b15aab124d22de9b-cgu.0[Internal]

0 commit comments

Comments
 (0)