Open JomerDev opened 3 weeks ago
Reduced:
fn test(x: bool) {
if x {
test(true);
}
}
fn main() {
test(true);
}
@rustbot claim
The current recursion analysis is fairly basic and is simply is not capable of catching the problem reported in this issue.
It does not take into account the arguments passed by the caller and emits warnings based on just one thing: whether all branches in the function recurse or not. If they do a warning is emitted but even if one of them does not recurse, no warning is emitted. That is pretty much it.
To illustrate, the following function will produce a warning under the current analysis because all branches in it recurse:
fn test(x: bool) {
if x {
test(true);
} else {
test(false);
}
}
but the following will not because the else
branch does not recurse:
fn test(x: bool) {
if x {
test(true);
} else {
return;
}
}
Note that the analysis completely ignores the fact that the else
branch will never be taken if the caller passes true
for x
, which shows that it does take into account the values of the arguments and how they are used in the function.
A more capable analysis that can catch the reported issue will have to be implemented based on some kind of data flow I'm guessing. However, one reason it may not yet have been implemented is that it may be slower.
Code
Current output
Desired output
Rationale and extra context
I made a mistake while writing the match seen above. I really wanted
Item::SubMenu(sub) => sub.test()
but mistakenly thoughtsub => sub.test()
will be enough. While the error was of course made by me, after I found it I was surprised that neither rustc, clippy nor rust-analyzer will warn me that this will cause infinite recursion. I ran the code on an embedded target which made the error search very hard, since any debug connection died when the stack overflowed without any error message, leading to a two day search for the causeOther cases
No response
Rust Version
Anything else?
No response