-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Recursive ..Default::default() overflows #128421
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
Comments
We already emit a warning explaining that it will recurse:
What do you expect to see changed? |
Would it make any sense to have deny rather than a warning by default because it is guaranteed to fail if called? |
I think that'd be a good idea. But also, maybe we could improve the lint in the 'recursive default impl' case specifically? Lots of people assume it will call |
Glad it's not just me haha... would it make sense if struct Foo {
bar: u32,
}
impl Default for Foo {
fn default() -> Self {
Self {..Default::default()}
}
} actually tried to use a default for each field, like u32::default() in this example? I think that is what the syntax kind of suggests should happen |
Nothing about it suggests it should use Default for each field. It's identical to writing e.g. you can do let a = Self { bar: 123 };
Self { ..a } |
@rustbot claim |
I tried this code:
I expected to see this happen: Default values for each field
Instead, this happened: Infinite recursion and stack overflow
Discussion
I know that what I was trying to do is not a supported syntax, but the overflow can be hard to debug and the warning is not super clear.
The text was updated successfully, but these errors were encountered: