about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorLeón Orell Valerian Liehr <me@fmease.dev>2025-01-29 06:03:23 +0100
committerGitHub <noreply@github.com>2025-01-29 06:03:23 +0100
commite37b744baedf8b13e021f94d3b8e4f7983b9cbd5 (patch)
treebda7b516a9b3225b3841d8e1ddad54d4170fa4b9 /compiler
parentbde47b7ae81103febb80b45f083ef2982859ad41 (diff)
parent0a9ee02d0a3ac8a45ab00b817c801f087a06828e (diff)
Rollup merge of #136168 - fmease:gci-fix-mono, r=compiler-errors
GCI: Don't try to eval / collect mono items inside overly generic free const items

Fixes #136156. Thanks for the pointers, errs!

There's one (preexisting) thing of note (maybe?). There's a difference between `const _: () = panic!();` and `const _<'a>: () = panic!();`: The former is a pre-mono error, the latter is a post-mono error. For comparison, both `fn _f() { const { panic!() } }` and `fn _f<'a: 'a>() { const { panic!() } }` are post-mono errors.

cc `@oli-obk`
r? compiler-errors or reassign
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_monomorphize/src/collector.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs
index bb603df1129..d53848f7461 100644
--- a/compiler/rustc_monomorphize/src/collector.rs
+++ b/compiler/rustc_monomorphize/src/collector.rs
@@ -1454,11 +1454,14 @@ impl<'v> RootCollector<'_, 'v> {
                 self.output.push(dummy_spanned(MonoItem::Static(def_id)));
             }
             DefKind::Const => {
-                // const items only generate mono items if they are
-                // actually used somewhere. Just declaring them is insufficient.
+                // Const items only generate mono items if they are actually used somewhere.
+                // Just declaring them is insufficient.
 
-                // but even just declaring them must collect the items they refer to
-                if let Ok(val) = self.tcx.const_eval_poly(id.owner_id.to_def_id()) {
+                // But even just declaring them must collect the items they refer to
+                // unless their generics require monomorphization.
+                if !self.tcx.generics_of(id.owner_id).requires_monomorphization(self.tcx)
+                    && let Ok(val) = self.tcx.const_eval_poly(id.owner_id.to_def_id())
+                {
                     collect_const_value(self.tcx, val, self.output);
                 }
             }