rust/compiler/rustc_monomorphize/src
Jonathan Brouwer 5cccc7ca02
Rollup merge of #151441 - Keith-Cancel:mgca3, r=BoxyUwU
Fix ICE: Don't try to evaluate type_consts when eagerly collecting items

This fixes https://github.com/rust-lang/rust/issues/151246

The change is pretty straightforward if the Monomorphization strategy is eager which `-Clink-dead-code=true` sets. This then would lead to the existing code to try and evaluate a `type const` which does not have a body to evaluate leading to an ICE. The change is pretty straight forward just skip over type consts.

This also seems like a sensible choice to me since a MonoItem can only be a Fn, Static, or Asm. A type const is none of the aforementioned.

And even if it was added to the MonoItems list it would then later fail this check:
fe98ddcfcf/compiler/rustc_monomorphize/src/collector.rs (L438-L440)
Since that explicitly checks that the MonoItem's `DefKind` is static and not anything else.

One more change is the addition of a simple test of the example code from https://github.com/rust-lang/rust/issues/151246 that checks that code compiles successfully with `-Clink-dead-code=true`.

The only other change was to make the guard checks a little easier to read by making the logic more linear instead of one big if statement.

r? @BoxyUwU
@rustbot label +F-associated_const_equality +F-min_generic_const_args
2026-01-22 13:35:42 +01:00
..
collector rlib handling 2025-11-19 00:17:37 -05:00
graph_checks Ensure that static initializers are acyclic for NVPTX 2026-01-06 17:00:21 +01:00
mono_checks mono: require target feature for scalable vectors 2025-12-16 11:01:26 +00:00
collector.rs Don't try to evaluate type_consts when eagerly collecting items. 2026-01-21 04:38:53 -08:00
errors.rs Ensure that static initializers are acyclic for NVPTX 2026-01-06 17:00:21 +01:00
lib.rs Bump stage0 2026-01-21 20:03:56 -05:00
partitioning.rs Remove Deref/DerefMut impl for Providers. 2026-01-14 15:55:59 +11:00
util.rs Move users of span_to_embeddable_string to span_to_diagnostic_string 2025-12-12 07:32:25 +01:00