1It is not allowed to manually call destructors in Rust.23Erroneous code example:45```compile_fail,E00406struct Foo {7 x: i32,8}910impl Drop for Foo {11 fn drop(&mut self) {12 println!("kaboom");13 }14}1516fn main() {17 let mut x = Foo { x: -7 };18 x.drop(); // error: explicit use of destructor method19}20```2122It is unnecessary to do this since `drop` is called automatically whenever a23value goes out of scope. However, if you really need to drop a value by hand,24you can use the `std::mem::drop` function:2526```27struct Foo {28 x: i32,29}30impl Drop for Foo {31 fn drop(&mut self) {32 println!("kaboom");33 }34}35fn main() {36 let mut x = Foo { x: -7 };37 drop(x); // ok!38}39```
Findings
✓ No findings reported for this file.