summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_error_codes/src/error_codes/E0040.md
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_error_codes/src/error_codes/E0040.md')
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0040.md39
1 files changed, 39 insertions, 0 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0040.md b/compiler/rustc_error_codes/src/error_codes/E0040.md
new file mode 100644
index 000000000..1373f8340
--- /dev/null
+++ b/compiler/rustc_error_codes/src/error_codes/E0040.md
@@ -0,0 +1,39 @@
+It is not allowed to manually call destructors in Rust.
+
+Erroneous code example:
+
+```compile_fail,E0040
+struct Foo {
+ x: i32,
+}
+
+impl Drop for Foo {
+ fn drop(&mut self) {
+ println!("kaboom");
+ }
+}
+
+fn main() {
+ let mut x = Foo { x: -7 };
+ x.drop(); // error: explicit use of destructor method
+}
+```
+
+It is unnecessary to do this since `drop` is called automatically whenever a
+value goes out of scope. However, if you really need to drop a value by hand,
+you can use the `std::mem::drop` function:
+
+```
+struct Foo {
+ x: i32,
+}
+impl Drop for Foo {
+ fn drop(&mut self) {
+ println!("kaboom");
+ }
+}
+fn main() {
+ let mut x = Foo { x: -7 };
+ drop(x); // ok!
+}
+```