Skip to content

fix: MIR evaluation of sized &T with recursive const fn#22030

Merged
ChayimFriedman2 merged 1 commit intorust-lang:masterfrom
Wilfred:pre-mir-relocation-test
Apr 13, 2026
Merged

fix: MIR evaluation of sized &T with recursive const fn#22030
ChayimFriedman2 merged 1 commit intorust-lang:masterfrom
Wilfred:pre-mir-relocation-test

Conversation

@Wilfred
Copy link
Copy Markdown
Contributor

@Wilfred Wilfred commented Apr 13, 2026

Previously, we didn't recurse in Evaluator::create_memory_map() or Evaluator::patch_addresses() when handling references with a known size.

This caused problems for hover rendering on const values, which would build a memory map for evaluated allocations and then pretty-printed values by following references through that map.

As a result, references in the map still pointed to the original addresses, meaning that the value pretty-printer would see the type parameters before substitution. This could cause stack overflows on well-formed Rust code using recursive const functions.

Add a regression test for hovering on a recursive const fn that previously caused stack overflow.

Fixes #21503

AI disclosure: I used Codex with GPT 5.4 to investigate the issue and write the initial version of this commit.

Previously, we didn't recurse in Evaluator::create_memory_map() or
Evaluator::patch_addresses() when handling references with a known
size.

This caused problems for hover rendering on const values, which would
build a memory map for evaluated allocations and then pretty-printed
values by following references through that map.

As a result, references in the map still pointed to the original addresses,
meaning that the value pretty-printer would see the type parameters
before substitution. This could cause stack overflows on well-formed
Rust code using recursive const functions.

Add a regression test for hovering on a recursive const fn that
previously caused stack overflow.

Fixes rust-lang#21503

AI disclosure: I used Codex with GPT 5.4 to investigate the issue and
write the initial version of this commit.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 13, 2026
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

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

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Apr 13, 2026
Merged via the queue into rust-lang:master with commit 2cce657 Apr 13, 2026
17 of 18 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 13, 2026
@Wilfred Wilfred deleted the pre-mir-relocation-test branch April 15, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stack overflow on recursive const values

3 participants