Skip to content

Commit a5fcc51

Browse files
Clean up E0040
1 parent cab1955 commit a5fcc51

File tree

1 file changed

+21
-4
lines changed
  • src/librustc_error_codes/error_codes

1 file changed

+21
-4
lines changed

src/librustc_error_codes/error_codes/E0040.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
It is not allowed to manually call destructors in Rust. It is also not
2-
necessary to do this since `drop` is called automatically whenever a value goes
3-
out of scope.
1+
It is not allowed to manually call destructors in Rust.
42

5-
Here's an example of this error:
3+
Erroneous code example:
64

75
```compile_fail,E0040
86
struct Foo {
@@ -20,3 +18,22 @@ fn main() {
2018
x.drop(); // error: explicit use of destructor method
2119
}
2220
```
21+
22+
It is unnecessary to do this since `drop` is called automatically whenever a
23+
value goes out of scope. However, if you really need to drop a value by hand,
24+
you can use the `std::mem::drop` function:
25+
26+
```
27+
struct Foo {
28+
x: i32,
29+
}
30+
impl Drop for Foo {
31+
fn drop(&mut self) {
32+
println!("kaboom");
33+
}
34+
}
35+
fn main() {
36+
let mut x = Foo { x: -7 };
37+
drop(x); // ok!
38+
}
39+
```

0 commit comments

Comments
 (0)