pub fn forget_unsized<T>(t: T)where
T: ?Sized,
forget_unsized)
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.
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/mem/fn.forget_unsized.html