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

Compiler cannot detect recursive Default::default() #87482

Closed
khachaturh opened this issue Jul 26, 2021 · 2 comments
Closed

Compiler cannot detect recursive Default::default() #87482

khachaturh opened this issue Jul 26, 2021 · 2 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@khachaturh
Copy link

khachaturh commented Jul 26, 2021

I tried this code:

#[derive(Debug)]
struct Foo {
flag: bool,
name: String,
id: i32,
}

impl Default for Foo {
fn default() -> Self {
Foo {
flag: true,
name: "Tom".to_string(),
..Default::default()
}
}
}

fn main() {
let foo = Foo::default();
println!("Foo - {:?}", foo);
}

I expected to see this happen: warning: function cannot return without recursing
--> src/main.rs:9:5
|
9 | fn default() -> Self {
| ^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
...
13 | ..Default::default()
| ------------------ recursive call site
|

Instead, this happened: no warnings
If I comment out the following line:
//name: "Tom".to_string(),
the warning is populated

Also you can check online
https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=8e13af07d962a2956955fc3d9f4869b0

Meta

rustc 1.53.0 (53cb7b0 2021-06-17)
binary: rustc
commit-hash: 53cb7b0
commit-date: 2021-06-17
host: x86_64-apple-darwin
release: 1.53.0
LLVM version: 12.0.1

1.53.0
Backtrace

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
Abort trap: 6

None

@khachaturh khachaturh added the C-bug Category: This is a bug. label Jul 26, 2021
@inquisitivecrystal inquisitivecrystal added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 29, 2021
@memoryruins
Copy link
Contributor

Duplicate of #78474

@ehuss
Copy link
Contributor

ehuss commented Jan 4, 2022

Closing as a duplicate of #78474.

@ehuss ehuss closed this as completed Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants