Detect recursive instantiation of generic functions #50043
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-type-system
Area: Type system
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-terse
Diagnostics: An error or lint that doesn't give enough information about the problem at hand.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
We currently have a quite helpful diagnostic for unconditionally recursive functions:
And infinitely sized recursive types:
But no good error for infinite instantiation of generic functions.
The following is minimized from @LPGhatguy's syntax tree library (original playground).
Here the instantiation of
print::<Json>
requires instantiatingprint::<Wrapper<Json>>
which callsprint::<Wrapper<Wrapper<Json>>
which callsprint::<Wrapper<Wrapper<Wrapper<Json>>>
... (The use case in this example is noteworthy because it is conceptually sensible; the trouble happens only when combined with Rust's approach of monomorphizing generic functions. Analogous code in Swift where generics are not monomorphized does not hit the same overflow.)As of rustc 1.27.0-nightly we get an unhelpful message with a recommendation that can't work. It would be better to detect this pattern of a generic function generating a tower of recursive instantiations.
The text was updated successfully, but these errors were encountered: