diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index ce17046969184..81d46e3b5b0d4 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1563,11 +1563,22 @@ impl<'v> RootCollector<'_, 'v> { // If we're collecting items eagerly, then recurse into all constants. // Otherwise the value is only collected when explicitly mentioned in other items. if self.strategy == MonoItemCollectionStrategy::Eager { - if !self.tcx.generics_of(id.owner_id).own_requires_monomorphization() - && let Ok(val) = self.tcx.const_eval_poly(id.owner_id.to_def_id()) - { - collect_const_value(self.tcx, val, self.output); + let def_id = id.owner_id.to_def_id(); + // Type Consts don't have bodies to evaluate + // nor do they make sense as a static. + if self.tcx.is_type_const(def_id) { + // FIXME(mgca): Is this actually what we want? We may want to + // normalize to a ValTree then convert to a const allocation and + // collect that? + return; + } + if self.tcx.generics_of(id.owner_id).own_requires_monomorphization() { + return; } + let Ok(val) = self.tcx.const_eval_poly(def_id) else { + return; + }; + collect_const_value(self.tcx, val, self.output); } } DefKind::Impl { of_trait: true } => { diff --git a/tests/ui/const-generics/mgca/type_const-incemental-compile.rs b/tests/ui/const-generics/mgca/type_const-incemental-compile.rs new file mode 100644 index 0000000000000..60e6968363db3 --- /dev/null +++ b/tests/ui/const-generics/mgca/type_const-incemental-compile.rs @@ -0,0 +1,11 @@ +//@ check-pass +//@compile-flags: -Clink-dead-code=true +// link-dead-code tries to eagerly monomorphize and collect items +// This lead to collector.rs to try and evaluate a type_const +// which will fail since they do not have bodies. +#![expect(incomplete_features)] +#![feature(min_generic_const_args)] + +#[type_const] +const TYPE_CONST: usize = 0; +fn main() {}