Skip to content

Recursive ..Default::default() overflows #128421

Open
@mj10021

Description

@mj10021

I tried this code:

#[derive(Debug)]
struct Foo {
    bar: u32
}

impl Default for Foo {
    fn default()-> Self {
        Self {
            ..Default::default()
        }
    }
}
fn main() {
    println!("{:?}",Foo::default());
}

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.

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-discussionCategory: Discussion or questions that doesn't represent real issues.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions