Skip to content

Conversation

@Wilfred
Copy link
Contributor

@Wilfred Wilfred commented Jan 21, 2026

This fixes #21503

AI disclosure: I minimised the crash manually and wrote the unit test, then asked Claude to write a fix. I've reviewed all the changes and they seem reasonable.

I'm in two minds about this solution: the sample code shouldn't produce an infinite recursion as far as I can see, so maybe there's a better fix. However, I also suspect it'd be possible to write a genuine infinite recursion const function, in which case you wouldn't want r-a to stack overflow even though the code wouldn't compile.

Let me know what you think.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 21, 2026
@rustbot

This comment has been minimized.

@Wilfred Wilfred force-pushed the hover_const_fun_recursion branch from 92c60bd to d8073f8 Compare January 21, 2026 16:20
@rustbot

This comment has been minimized.

@Wilfred Wilfred force-pushed the hover_const_fun_recursion branch from d8073f8 to 7738031 Compare January 21, 2026 16:56
@rustbot
Copy link
Collaborator

rustbot commented Jan 21, 2026

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

@ChayimFriedman2
Copy link
Contributor

I don't think it can be possible to create an infinite recursion. When evaluating yes, but not when rendering.

@Wilfred
Copy link
Contributor Author

Wilfred commented Jan 22, 2026

@ChayimFriedman2 It shouldn't be possible, but it definitely is today unfortunately -- see the test added.

Perhaps the type parameters aren't being substituted correctly? It looks like rendering is infinitely recursing on Option<()>::SIGNATURE instead of recursing into ()::SIGNATURE as it should.

@Veykril
Copy link
Member

Veykril commented Jan 23, 2026

Didn't we have a similar issue with impl Trait where trait Trait<T = Self> overflowing. How did we solve that? Feels like we could take a similar approach here as well.

@ShoyuVanilla
Copy link
Member

ShoyuVanilla commented Jan 23, 2026

#16877
I'm not sure is this what you are mentioning but you've introduced generic_args_sans_defaults 😄

@Veykril
Copy link
Member

Veykril commented Jan 23, 2026

Ah, right, we didn't solve it I worked around it 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stack overflow on recursive const values

5 participants