-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
@@ -265,6 +265,8 @@ mir_build_pointer_pattern = function pointers and raw pointers not derived from | |||
mir_build_privately_uninhabited = pattern `{$witness_1}` is currently uninhabited, but this variant contains private fields which may become inhabited in the future | |||
mir_build_recursive_default_impl = calling ..Default::default() in a Default implementation leads to infinite recursion, and cannotbe used to 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.
mir_build_recursive_default_impl = calling ..Default::default() in a Default implementation leads to infinite recursion, and cannotbe used to initialize the fields of a struct or enum | |
mir_build_recursive_default_impl = 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.
why did you not fix the backticks?
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.
oops my mistake sorry
use rustc_span::def_id::LocalDefId; | ||
use rustc_span::sym; |
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.
put these imports at the top of the file.
8f7ca38
to
23ee908
Compare
23ee908
to
d9ee420
Compare
Fixes #128421, where it was pointed out that recursion in default impls can be confusing and always results in failure.