about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJubilee <workingjubilee@gmail.com>2025-02-14 14:05:27 -0800
committerGitHub <noreply@github.com>2025-02-14 14:05:27 -0800
commitbaa5a76b97398bb3cef5f69a5a5ec0a201ba8a42 (patch)
treeba46ece7e21815f77f14b9bf1cc21d031ee805fb
parent69dbedd13ebce4ce0e0a43808c2399e07ed38493 (diff)
parent2ada9ccb7d144075a6270aa94c20718be377148f (diff)
downloadrust-baa5a76b97398bb3cef5f69a5a5ec0a201ba8a42.tar.gz
rust-baa5a76b97398bb3cef5f69a5a5ec0a201ba8a42.zip
Rollup merge of #137035 - compiler-errors:eagerly-mono-closures-after-norm, r=saethlin
Normalize closure instance before eagerly monomorphizing it

We were monomorphizing two versions of the closure (or in the original issue, coroutine) -- one with normalized captures and one with unnormalized captures. This led to a symbol collision.

Fixes #137009

r? `@saethlin` or reassign
-rw-r--r--compiler/rustc_monomorphize/src/collector.rs7
-rw-r--r--tests/ui/closures/eager-mono-with-normalizable-upvars.rs19
2 files changed, 26 insertions, 0 deletions
diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs
index ae31ed59391..e4a733fcbce 100644
--- a/compiler/rustc_monomorphize/src/collector.rs
+++ b/compiler/rustc_monomorphize/src/collector.rs
@@ -1509,6 +1509,13 @@ impl<'v> RootCollector<'_, 'v> {
                         }
                         _ => unreachable!(),
                     };
+                    let Ok(instance) = self.tcx.try_normalize_erasing_regions(
+                        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);
diff --git a/tests/ui/closures/eager-mono-with-normalizable-upvars.rs b/tests/ui/closures/eager-mono-with-normalizable-upvars.rs
new file mode 100644
index 00000000000..4d934f7a7a9
--- /dev/null
+++ b/tests/ui/closures/eager-mono-with-normalizable-upvars.rs
@@ -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()();
+}