-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-destructorsArea: Destructors (`Drop`, …)Area: Destructors (`Drop`, …)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
If you instantiate the same struct in the Drop function, the program will loop indefinitely and crash.
The Code
struct ToDrop;
impl Drop for ToDrop {
fn drop(&mut self) {
let m = ToDrop;
println!( "ToDrop is being dropped" );
}
}
fn main() {
let x = ToDrop;
}
Well, I expected the compiler to catch this at compilation. So this could be an area of improvement.
Here is another variation that also causes a stackoverflow without intializing the same variable
struct A;
struct B;
impl Drop for A {
fn drop( &mut self ) {
let b = B;
}
}
impl Drop for B {
fn drop( &mut self ) {
let a = A;
}
}
fn main() {
let a = A;
}
The error message at execution
thread 'main' has overflowed its stack
fatal runtime error: stack overflow
Abort trap: 6
Metadata
Metadata
Assignees
Labels
A-destructorsArea: Destructors (`Drop`, …)Area: Destructors (`Drop`, …)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.