]> git.lizzy.rs Git - rust.git/blob - src/docs/forget_copy.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / forget_copy.txt
1 ### What it does
2 Checks for calls to `std::mem::forget` with a value that
3 derives the Copy trait
4
5 ### Why is this bad?
6 Calling `std::mem::forget` [does nothing for types that
7 implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the
8 value will be copied and moved into the function on invocation.
9
10 An alternative, but also valid, explanation is that Copy types do not
11 implement
12 the Drop trait, which means they have no destructors. Without a destructor,
13 there
14 is nothing for `std::mem::forget` to ignore.
15
16 ### Example
17 ```
18 let x: i32 = 42; // i32 implements Copy
19 std::mem::forget(x) // A copy of x is passed to the function, leaving the
20                     // original unaffected
21 ```