Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mj10021
Copy link
Contributor

@mj10021 mj10021 commented Aug 6, 2024

Fixes #128421, where it was pointed out that recursion in default impls can be confusing and always results in failure.

@rustbot
Copy link
Collaborator

rustbot commented Aug 6, 2024

r? @chenyukang

rustbot has assigned @chenyukang.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 6, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@compiler-errors compiler-errors left a 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,
Copy link
Member

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.

@mj10021
Copy link
Contributor Author

mj10021 commented Aug 6, 2024

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.

Do you think that it makes sense for the Self { ..Default::default() } case to be denied since it is a guaranteed infinite loop or it is too specific off a case to warrant special treatment?

@mj10021
Copy link
Contributor Author

mj10021 commented Aug 6, 2024

@rustbot label +T-Lang

@rustbot rustbot added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Aug 6, 2024
@chenyukang
Copy link
Member

yeah, I think it's better to change the wording for existing lint for this specific scenario.

@chenyukang
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 24, 2024
@compiler-errors compiler-errors self-assigned this Aug 24, 2024
@bors
Copy link
Contributor

bors commented Sep 23, 2024

☔ The latest upstream changes (presumably #130724) made this pull request unmergeable. Please resolve the merge conflicts.

@alex-semenyuk
Copy link
Member

@mj10021
From wg-triage. Do you have update on this PR?

@mj10021
Copy link
Contributor Author

mj10021 commented Oct 31, 2024

@mj10021 From wg-triage. Do you have update on this PR?

Oops, this got away from me, will update the PR shortly

@mj10021
Copy link
Contributor Author

mj10021 commented Nov 5, 2024

Does this look more like the type of note that was in mind?

@Dylan-DPC Dylan-DPC added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 6, 2024
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 21, 2024
@mj10021
Copy link
Contributor Author

mj10021 commented Nov 24, 2024

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 24, 2024
Copy link
Member

@compiler-errors compiler-errors left a 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
Copy link
Member

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.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 16, 2024
@compiler-errors
Copy link
Member

r? compiler

@bors
Copy link
Contributor

bors commented Dec 18, 2024

☔ The latest upstream changes (presumably #134470) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC
Copy link
Member

@mj10021 any updates on this pr? thanks

@mj10021
Copy link
Contributor Author

mj10021 commented Mar 3, 2025

@mj10021 any updates on this pr? thanks

Sorry, I thought the PR was rejected, are these changes still wanted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Recursive ..Default::default() overflows
9 participants