forget_unsized in core::mem - Rust
Description: Like `forget`, but also accepts unsized values.

## forget_unsized

# Function forget_unsized

Source

    pub fn forget_unsized<T: ?Sized>(t: T)

🔬This is a nightly-only experimental API. (`forget_unsized`)
Expand description

Like `forget`, but also accepts unsized values.

While Rust does not permit unsized locals since its removal in #111942 it is still possible to call functions with unsized values from a function argument or place expression.

    #![feature(unsized_fn_params, forget_unsized)]
    #![allow(internal_features)]

    use std::mem::forget_unsized;

    pub fn in_place() {
        forget_unsized(*Box::<str>::from("str"));
    }

    pub fn param(x: str) {
        forget_unsized(x);
    }

This works because the compiler will alter these functions to pass the parameter by reference instead. This trick is necessary to support `Box<dyn FnOnce()>: FnOnce()`. See #68304 and #71170 for more information.