Recursive ..Default::default() overflows
Open
@mj10021 is already working on this.
Since Aug 4, 2024.
A-lints
C-discussion
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.