Skip to content

Fix const normalization for generic const items with trait assoc consts#152278

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
lapla-cogito:type_const_nested
Feb 15, 2026
Merged

Fix const normalization for generic const items with trait assoc consts#152278
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
lapla-cogito:type_const_nested

Conversation

@lapla-cogito
Copy link
Contributor

@lapla-cogito lapla-cogito commented Feb 7, 2026

In try_fold_free_or_assoc, the check for whether the normalization result needs further normalization only considered types, not constants. This caused generic const items marked with #[type_const] that reference trait associated consts to only partially normalize—the outer const would be expanded, but the inner associated const would remain unevaluated, resulting in an ICE in borrowck.

close #151647

r? BoxyUwU
(Based on git blame)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 7, 2026
Comment on lines 381 to +386
if res != term.to_term(tcx)
&& (res.as_type().map_or(false, |t| t.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION))
|| term.kind(tcx) == ty::AliasTermKind::FreeTy)
&& (res.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION)
|| matches!(
term.kind(tcx),
ty::AliasTermKind::FreeTy | ty::AliasTermKind::FreeConst
))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect this to just be if term.has_aliases() and I don't understand why it isn't. Can you try changing it to that and see if anything breaks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think term.has_aliases() is not a proper solution (though I didn't know that API). Actually it caused a SEGV during stage1 lib building:

output (extracted)
Building stage1 library artifacts (stage1 -> stage1, x86_64-unknown-linux-gnu)
   Compiling compiler_builtins v0.1.160 (/home/lapla/repos/rust/library/compiler-builtins/compiler-builtins)
   Compiling core v0.0.0 (/home/lapla/repos/rust/library/core)
   Compiling libc v0.2.178
   Compiling object v0.37.3
   Compiling std v0.0.0 (/home/lapla/repos/rust/library/std)
   Compiling test v0.0.0 (/home/lapla/repos/rust/library/test)
error: rustc interrupted by SIGSEGV, printing backtrace

/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x93ee8c) [0x7bd87833ee8c]
/usr/lib/x86_64-linux-gnu/libc.so.6(+0x45f30) [0x7bd877645f30]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x313ad45) [0x7bd87ab3ad45]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x32f10d9) [0x7bd87acf10d9]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x335e113) [0x7bd87ad5e113]

### cycle encountered after 5 frames with period 6
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(_RNvXs_NtNtNtCsiiExf7IvESp_21rustc_trait_selection6traits5query9normalizeNtB4_15QueryNormalizerINtNtCs44sggCrMDsM_13rustc_type_ir4fold18FallibleTypeFolderNtNtNtCsforUfnDCdfO_12rustc_middle2ty7context6TyCtxtE11try_fold_ty+0x1ca) [0x7bd87ad71e1a]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x335e82e) [0x7bd87ad5e82e]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(_RNvXs_NtNtNtCsiiExf7IvESp_21rustc_trait_selection6traits5query9normalizeNtB4_15QueryNormalizerINtNtCs44sggCrMDsM_13rustc_type_ir4fold18FallibleTypeFolderNtNtNtCsforUfnDCdfO_12rustc_middle2ty7context6TyCtxtE11try_fold_ty+0x1ca) [0x7bd87ad71e1a]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x335e82e) [0x7bd87ad5e82e]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(_RNvXs_NtNtNtCsiiExf7IvESp_21rustc_trait_selection6traits5query9normalizeNtB4_15QueryNormalizerINtNtCs44sggCrMDsM_13rustc_type_ir4fold18FallibleTypeFolderNtNtNtCsforUfnDCdfO_12rustc_middle2ty7context6TyCtxtE11try_fold_ty+0x1ca) [0x7bd87ad71e1a]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x335e82e) [0x7bd87ad5e82e]
### recursed 41 times

/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(_RNvXs_NtNtNtCsiiExf7IvESp_21rustc_trait_selection6traits5query9normalizeNtB4_15QueryNormalizerINtNtCs44sggCrMDsM_13rustc_type_ir4fold18FallibleTypeFolderNtNtNtCsforUfnDCdfO_12rustc_middle2ty7context6TyCtxtE11try_fold_ty+0x1ca) [0x7bd87ad71e1a]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x335e82e) [0x7bd87ad5e82e]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(_RNvXs_NtNtNtCsiiExf7IvESp_21rustc_trait_selection6traits5query9normalizeNtB4_15QueryNormalizerINtNtCs44sggCrMDsM_13rustc_type_ir4fold18FallibleTypeFolderNtNtNtCsforUfnDCdfO_12rustc_middle2ty7context6TyCtxtE11try_fold_ty+0x1ca) [0x7bd87ad71e1a]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x335e82e) [0x7bd87ad5e82e]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(_RNvXs_NtNtNtCsiiExf7IvESp_21rustc_trait_selection6traits5query9normalizeNtB4_15QueryNormalizerINtNtCs44sggCrMDsM_13rustc_type_ir4fold18FallibleTypeFolderNtNtNtCsforUfnDCdfO_12rustc_middle2ty7context6TyCtxtE11try_fold_ty+0x1ca) [0x7bd87ad71e1a]

note: rustc unexpectedly overflowed its stack! this is a bug
note: maximum backtrace depth reached, frames may have been lost
note: we would appreciate a report at https://github.com/rust-lang/rust
help: you can increase rustc's stack size by setting RUST_MIN_STACK=16777216
note: backtrace dumped due to SIGSEGV! resuming signal
rustc exited with signal: 11 (SIGSEGV) (core dumped)
error: could not compile `core` (lib)

Caused by:
  process didn't exit successfully: `/home/lapla/repos/rust/build/bootstrap/debug/rustc /home/lapla/repos/rust/build/bootstrap/debug/rustc --crate-name core --edition=2024 library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=130 --crate-type lib --emit=dep-info,metadata,link -Z embed-metadata=no -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 --warn=unexpected_cfgs --check-cfg 'cfg(no_fp_fmt_parse)' --check-cfg 'cfg(feature, values(any()))' --check-cfg 'cfg(target_has_reliable_f16)' --check-cfg 'cfg(target_has_reliable_f16_math)' --check-cfg 'cfg(target_has_reliable_f128)' --check-cfg 'cfg(target_has_reliable_f128_math)' --check-cfg 'cfg(llvm_enzyme)' -Cembed-bitcode=yes -Zunstable-options -Cforce-frame-pointers=non-leaf --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values("debug_refcell", "llvm_enzyme", "optimize_for_size", "panic_immediate_abort"))' -C metadata=d728f96fea50222e -C extra-filename=-15fde4dd13344f6e --out-dir /home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/dist/deps --target x86_64-unknown-linux-gnu -C linker=clang -L dependency=/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/dist/deps -L dependency=/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1-std/dist/deps -Zannotate-moves '--check-cfg=cfg(feature,values(any()))' -Zunstable-options -Zmacro-backtrace -Csplit-debuginfo=off -Cprefer-dynamic -Zinline-mir -Zinline-mir-preserve-debug -Zmir_strip_debuginfo=locals-in-tiny-functions -Clink-args=-Wl,-z,origin '-Clink-args=-Wl,-rpath,$ORIGIN/../lib' -Alinker-messages '-Zcrate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/")' -Z binary-dep-depinfo` (exit status: 254)
Build completed unsuccessfully in 0:04:56

HAS_ALIAS includes HAS_TY_OPAQUE, and opaque types are not normalized outside of TypingMode::PostAnalysis, so the res!=term.to_term(tcx) condition keeps passing and the recursion never terminates.

I also found needs_normalization(), which excludes HAS_TY_OPAQUE depending on the typing mode, but it still includes HAS_TY_PROJECTION and others, which similarly caused a stack overflow. Since projection types are already handled directly by try_fold_ty, the re-normalization here should only need HAS_CT_PROJECTION and the FreeTy/FreeConst cases (as normalize_canonicalized_free_alias() only unwraps one layer) I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks :3

@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 14, 2026

@rustbot author

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 14, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 14, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 14, 2026
@lapla-cogito
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 15, 2026
@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 15, 2026

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 15, 2026

📌 Commit cb84a82 has been approved by BoxyUwU

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 15, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 15, 2026
…BoxyUwU

Fix const normalization for generic const items with trait assoc consts

In `try_fold_free_or_assoc`, the check for whether the normalization result needs further normalization only considered types, not constants. This caused generic const items marked with `#[type_const]` that reference trait associated consts to only partially normalize—the outer const would be expanded, but the inner associated const would remain unevaluated, resulting in an ICE in borrowck.

close rust-lang#151647

r? BoxyUwU
(Based on git blame)
@JonathanBrouwer
Copy link
Contributor

@bors r-
#152656 (comment)

@rust-bors rust-bors bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 15, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 15, 2026

Commit cb84a82 has been unapproved.

This PR was contained in a rollup (#152656), which was also unapproved.

@rustbot
Copy link
Collaborator

rustbot commented Feb 15, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@lapla-cogito
Copy link
Contributor Author

Looks like #152324 is the cause. I've rebased.

@JonathanBrouwer
Copy link
Contributor

@bors r=BoxyUwU

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 15, 2026

📌 Commit 55f56f2 has been approved by BoxyUwU

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 15, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 15, 2026
…BoxyUwU

Fix const normalization for generic const items with trait assoc consts

In `try_fold_free_or_assoc`, the check for whether the normalization result needs further normalization only considered types, not constants. This caused generic const items marked with `#[type_const]` that reference trait associated consts to only partially normalize—the outer const would be expanded, but the inner associated const would remain unevaluated, resulting in an ICE in borrowck.

close rust-lang#151647

r? BoxyUwU
(Based on git blame)
@rust-bors rust-bors bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 15, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 15, 2026

⚠️ A new commit 88f0ac34dce0e0d21da576aa111ce3b7d66bfafc was pushed to the branch, the PR will need to be re-approved.

@lapla-cogito
Copy link
Contributor Author

@JonathanBrouwer Sorry, we still need to make some changes to pass CI. This should be fine now.

@JonathanBrouwer
Copy link
Contributor

I'll wait for CI to pass and then reapprove :P

@lapla-cogito
Copy link
Contributor Author

CI is now all green :)

@JonathanBrouwer
Copy link
Contributor

@bors r=BoxyUwU

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 15, 2026

📌 Commit 88f0ac3 has been approved by BoxyUwU

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 15, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 15, 2026
…BoxyUwU

Fix const normalization for generic const items with trait assoc consts

In `try_fold_free_or_assoc`, the check for whether the normalization result needs further normalization only considered types, not constants. This caused generic const items marked with `#[type_const]` that reference trait associated consts to only partially normalize—the outer const would be expanded, but the inner associated const would remain unevaluated, resulting in an ICE in borrowck.

close rust-lang#151647

r? BoxyUwU
(Based on git blame)
rust-bors bot pushed a commit that referenced this pull request Feb 15, 2026
…uwer

Rollup of 4 pull requests

Successful merges:

 - #152566 (Remove code for ThinLTO from cg_gcc)
 - #152278 (Fix const normalization for generic const items with trait assoc consts)
 - #152604 (Relocate some tests)
 - #152625 (Provide all lint group names to Clippy)
@rust-bors rust-bors bot merged commit 8b3ef9e into rust-lang:main Feb 15, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Feb 15, 2026
rust-timer added a commit that referenced this pull request Feb 15, 2026
Rollup merge of #152278 - lapla-cogito:type_const_nested, r=BoxyUwU

Fix const normalization for generic const items with trait assoc consts

In `try_fold_free_or_assoc`, the check for whether the normalization result needs further normalization only considered types, not constants. This caused generic const items marked with `#[type_const]` that reference trait associated consts to only partially normalize—the outer const would be expanded, but the inner associated const would remain unevaluated, resulting in an ICE in borrowck.

close #151647

r? BoxyUwU
(Based on git blame)
@lapla-cogito lapla-cogito deleted the type_const_nested branch February 16, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE: mGCA+GCI: Broken MIR: equate_normalized_input_or_output: NoSolution

4 participants