pub fn forget_unsized<T>(t: T)where
T: ?Sized,
🔬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 in-place construction.
#![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.