-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new lint: Recursive Display
impl
#2691
Comments
Huh, it's funny that this doesn't trigger the unconditional recursion lint upstream. I'd consider this to be a compiler bug. |
I suspect that's because the formatting machinery goes through some intermediate functions. |
Ah right, the lint only checks one layer of function calls, so |
any update here :) ? This would be an awesome lint! |
There is the |
Display
impl
new lint: `recursive_format_impl` The to_string_in_display lint is renamed to recursive_format_impl A check is added for the use of self formatted with Display or Debug inside any format string in the same impl The to_string_in_display check is kept as is - like in the format_in_format_args lint This is my first contribution so please check it for better / more idiomatic checks + error messages. Note the format macro paths are shared with the `format_in_format_args` lint - maybe those could be moved to clippy utils too. This relates to issues #2691 and #7830 ------ changelog: Renamed `to_string_in_display` lint to [`recursive_format_impl`] with new check for any use of self as Display or Debug inside the same format trait impl.
It looks like that the |
It's possible to implement Display trait in such a way which recursively calls itself until stack is exhausted. There's probably more variations how to encounter this bug. I provide one example.
Consider the following code:
Compiles perfectly fine, but there's stack trace at run time:
The bug is in line
write!(f, "{}", self)
which recursively calls itself by trying to use Display trait implementation for self.The text was updated successfully, but these errors were encountered: