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>
This commit is contained in:
parent
d276646872
commit
7635702d06
2 changed files with 26 additions and 4 deletions
|
|
@ -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 } => {
|
||||
|
|
|
|||
|
|
@ -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() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue