Causing stack overflow by calling to_string in Display trait implementation #63652
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.
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
As a mentor on exercism.io I came across the following code:
This causes a stack overflow: The reason for that being that to_string is automatically implemented by the Display trait - which generates a loop. At least that is my explaination.
Is there a way for the compiler to catch mistakes like this? This is actually the first time i really saw someone generate a runtime error with safe rust (except for panics of course).
The text was updated successfully, but these errors were encountered: