-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Add lint for recursive default impls #128737
base: master
Are you sure you want to change the base?
Conversation
r? @chenyukang rustbot has assigned @chenyukang. Use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
I don't think this should be a new lint. We already have a lint for when we detect recursive calls, and we can change the wording for that lint if we detect that it's a recursive Default
invocation.
/// default struct for this field. This will always lead to an infinite loop | ||
/// so it is denied. | ||
pub RECURSIVE_DEFAULT_IMPL, | ||
Deny, |
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.
This needs T-lang approval if it's going to be a Deny
lint.
Do you think that it makes sense for the |
@rustbot label +T-Lang |
yeah, I think it's better to change the wording for existing lint for this specific scenario. |
@rustbot author |
☔ The latest upstream changes (presumably #130724) made this pull request unmergeable. Please resolve the merge conflicts. |
@mj10021 |
Oops, this got away from me, will update the PR shortly |
9547a7f
to
9c0ccb3
Compare
Does this look more like the type of note that was in mind? |
9c0ccb3
to
8f7ca38
Compare
8f7ca38
to
23ee908
Compare
23ee908
to
d9ee420
Compare
@rustbot review |
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.
I don't think that this change carries enough benefit, especially b/c I don't believe we can actually tell we're actually in a FRU to make this note accurate.
@@ -122,6 +122,7 @@ LL | let x = Default::default(); | |||
| ------------------ recursive call site | |||
| | |||
= help: a `loop` may express intention better if this is on purpose | |||
= help: calling `..Default::default()` in a `Default` implementation leads to infinite recursion, and does not initialize the fields of a struct or enum |
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.
This is evidence of false positives for this lint.
r? compiler |
☔ The latest upstream changes (presumably #134470) made this pull request unmergeable. Please resolve the merge conflicts. |
@mj10021 any updates on this pr? thanks |
Sorry, I thought the PR was rejected, are these changes still wanted? |
Fixes #128421, where it was pointed out that recursion in default impls can be confusing and always results in failure.