diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2019-11-15 13:16:47 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2019-11-15 13:24:47 +0100 |
| commit | a5fcc5137f2b07d176c8d915a2b609462ee3a32c (patch) | |
| tree | 2261526815248deb4fdab1cc09950f92d4b0af6f | |
| parent | cab1955b216f2b84c6129a0b734c89419f565b4a (diff) | |
| download | rust-a5fcc5137f2b07d176c8d915a2b609462ee3a32c.tar.gz rust-a5fcc5137f2b07d176c8d915a2b609462ee3a32c.zip | |
Clean up E0040
| -rw-r--r-- | src/librustc_error_codes/error_codes/E0040.md | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/librustc_error_codes/error_codes/E0040.md b/src/librustc_error_codes/error_codes/E0040.md index fb262018c35..1373f8340d8 100644 --- a/src/librustc_error_codes/error_codes/E0040.md +++ b/src/librustc_error_codes/error_codes/E0040.md @@ -1,8 +1,6 @@ -It is not allowed to manually call destructors in Rust. It is also not -necessary to do this since `drop` is called automatically whenever a value goes -out of scope. +It is not allowed to manually call destructors in Rust. -Here's an example of this error: +Erroneous code example: ```compile_fail,E0040 struct Foo { @@ -20,3 +18,22 @@ fn main() { 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! +} +``` |
