Detect heterogeneous generic recursion usage pre-monomorphization #90289
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
(Request inspired by #90063 (comment), after I wrote compiles-but-never-works code in https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#the-opscontrolflow-type )
Given the following (minimal example) code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=584d7b447db0f7890d2f94c3b945640e
The current output is: no errors nor warnings
However, if it's ever called, it'll give an error like
It would be nice for the compiler to detect, pre-monomorphization, that this will never actually work because any possible monomorphization will end up requiring instantiating another additional monomorphization.
(Not catching all cases would be fine -- I suspect indirect recursion would be particularly annoying to detect well. Maybe a deny-by-default lint for this? It'd technically be a breaking change to make it a hard error, and I don't think it really needs to be hard error. The lint is enough.)
The text was updated successfully, but these errors were encountered: