unconditional recursion warning not displayed when passing &self #67932
Labels
A-lints
Area: Lints (warnings about flaws in source code) such as unused_mut.
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Today I hit a segfault caused by stack overflow that wasn't caught by the compiler. This only occurred in debug mode, not release.
Current Behavior
The cause was the following piece of code, which passes the compiler without emitting any warnings:
playground
As would be obvious to most people carefully reviewing this code, there's a clear case of unconditional recursion happening. We pass
&self
to the same impl over and over.Expected behavior
A similar case is already caught by the compiler: passing
self
rather than&self
to the same impl. This triggers the "unconditional recursion" warning. I would've expected the&self
case to hit the same warning.playground
It'd be nice if the
&self
case would also emit diagnostics when detecting infinite recursion. Seeing a segfault occur in your program can be pretty scary. Added to that it wasn't triggering for us in release mode, and searching for "debug stack overflow rust" yields some pretty poor results (because "stack overflow" is also the name of a popular website, heh).This seems like a case where we could probably use better diagnostics. Thanks!
The text was updated successfully, but these errors were encountered: