Skip to content

Commit 7635702

Browse files
Keith-CancelBoxyUwU
andcommitted
Don't try to evaluate type_consts when eagerly collecting items.
Update compiler/rustc_monomorphize/src/collector.rs Add FIXME(mgca) comment to potentially re-investigate in the future. Co-Authored-By: Boxy <rust@boxyuwu.dev>
1 parent d276646 commit 7635702

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,11 +1563,22 @@ impl<'v> RootCollector<'_, 'v> {
15631563
// If we're collecting items eagerly, then recurse into all constants.
15641564
// Otherwise the value is only collected when explicitly mentioned in other items.
15651565
if self.strategy == MonoItemCollectionStrategy::Eager {
1566-
if !self.tcx.generics_of(id.owner_id).own_requires_monomorphization()
1567-
&& let Ok(val) = self.tcx.const_eval_poly(id.owner_id.to_def_id())
1568-
{
1569-
collect_const_value(self.tcx, val, self.output);
1566+
let def_id = id.owner_id.to_def_id();
1567+
// Type Consts don't have bodies to evaluate
1568+
// nor do they make sense as a static.
1569+
if self.tcx.is_type_const(def_id) {
1570+
// FIXME(mgca): Is this actually what we want? We may want to
1571+
// normalize to a ValTree then convert to a const allocation and
1572+
// collect that?
1573+
return;
1574+
}
1575+
if self.tcx.generics_of(id.owner_id).own_requires_monomorphization() {
1576+
return;
15701577
}
1578+
let Ok(val) = self.tcx.const_eval_poly(def_id) else {
1579+
return;
1580+
};
1581+
collect_const_value(self.tcx, val, self.output);
15711582
}
15721583
}
15731584
DefKind::Impl { of_trait: true } => {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ check-pass
2+
//@compile-flags: -Clink-dead-code=true
3+
// link-dead-code tries to eagerly monomorphize and collect items
4+
// This lead to collector.rs to try and evaluate a type_const
5+
// which will fail since they do not have bodies.
6+
#![expect(incomplete_features)]
7+
#![feature(min_generic_const_args)]
8+
9+
#[type_const]
10+
const TYPE_CONST: usize = 0;
11+
fn main() {}

0 commit comments

Comments
 (0)