-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Extend UNCONDITIONAL_RECURSION to check for ToString implementations #11980
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
Extend UNCONDITIONAL_RECURSION to check for ToString implementations #11980
Conversation
381531e
to
efddb33
Compare
impl std::string::ToString for S6 { | ||
fn to_string(&self) -> String { | ||
//~^ ERROR: function cannot return without recursing | ||
self.to_string() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps add another test where self
is put into a local before calling its to_string
?
And another one calling (self as &Self).to_string()
just for extra fun? 😋
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps add another test where
self
is put into a local before calling itsto_string
?
For that one, we agree that it's just for cases like:
let x = self;
x.to_string()
and nothing else? Because otherwise it becomes quite tricky to check if self
was mutated... However if you know of a way to check it, I'm very interested. :)
And another one calling
(self as &Self).to_string()
just for extra fun? 😋
Sure. ^^'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However if you know of a way to check it, I'm very interested. :)
There's the clippy_utils::expr_or_init function, which should be helpful for that.
@rustbot author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
efddb33
to
d161f3b
Compare
Updated and added the suggested tests. :) |
Thank you! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Follow-up of #11938.
r? @llogiq
changelog: Extend
UNCONDITIONAL_RECURSION
to check forToString
implementations