summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/forget_copy.txt
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/src/docs/forget_copy.txt')
-rw-r--r--src/tools/clippy/src/docs/forget_copy.txt21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/tools/clippy/src/docs/forget_copy.txt b/src/tools/clippy/src/docs/forget_copy.txt
new file mode 100644
index 000000000..1d100912e
--- /dev/null
+++ b/src/tools/clippy/src/docs/forget_copy.txt
@@ -0,0 +1,21 @@
+### What it does
+Checks for calls to `std::mem::forget` with a value that
+derives the Copy trait
+
+### Why is this bad?
+Calling `std::mem::forget` [does nothing for types that
+implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the
+value will be copied and moved into the function on invocation.
+
+An alternative, but also valid, explanation is that Copy types do not
+implement
+the Drop trait, which means they have no destructors. Without a destructor,
+there
+is nothing for `std::mem::forget` to ignore.
+
+### Example
+```
+let x: i32 = 42; // i32 implements Copy
+std::mem::forget(x) // A copy of x is passed to the function, leaving the
+ // original unaffected
+``` \ No newline at end of file