Closed
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