Add lint for recursive default impls#128737
Add lint for recursive default impls#128737mj10021 wants to merge 2 commits intorust-lang:masterfrom
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.
compiler-errors
left a comment
There was a problem hiding this comment.
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.
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 |
compiler-errors
left a comment
There was a problem hiding this comment.
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.
| | ------------------ 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.
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? |
|
@mj10021 ah i was waiting to see if maybe there is some solution to this. I guess not, so I'm fine with closing it. Thanks for contributing. |
Fixes #128421, where it was pointed out that recursion in default impls can be confusing and always results in failure.