FORGETTING_COPY_TYPES in rustc_lint::drop_forget_useless - Rust
Description: The `forgetting_copy_types` lint checks for calls to `std::mem::forget` with a value that derives the Copy trait.

Skip to main content

## FORGETTING_COPY_TYPES

# Static FORGETTING_COPY_TYPES

Source

    pub static FORGETTING_COPY_TYPES: &Lint

Expand description

The `forgetting_copy_types` lint checks for calls to `std::mem::forget` with a value that derives the Copy trait.

#### §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

{{produces}}

#### §Explanation

Calling `std::mem::forget` does nothing for types that implement Copy 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.