Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compiler/rustc_monomorphize/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,13 @@ impl<'v> RootCollector<'_, 'v> {
}
_ => unreachable!(),
};
let Ok(instance) = self.tcx.try_normalize_erasing_regions(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is unnecessarily defensive but i'd rather not turn this into an ICE with an impossible-to-normalize opaque type or something.

ty::TypingEnv::fully_monomorphized(),
instance,
) else {
// Don't ICE on an impossible-to-normalize closure.
return;
};
let mono_item = create_fn_mono_item(self.tcx, instance, DUMMY_SP);
if mono_item.node.is_instantiable(self.tcx) {
self.output.push(mono_item);
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/closures/eager-mono-with-normalizable-upvars.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//@ compile-flags: -Clink-dead-code -Csymbol-mangling-version=v0
//@ build-pass

// Ensure that when eagerly collecting `test::{closure#0}`, we don't try
// collecting an unnormalized version of the closure (specifically its
// upvars), since the closure captures the RPIT `opaque::{opaque#0}`.

fn opaque() -> impl Sized {}

fn test() -> impl FnOnce() {
let opaque = opaque();
move || {
let opaque = opaque;
}
}

fn main() {
test()();
}
Loading