Rollup merge of #55785 - stjepang:unsized-drop-forget, r=alexcrichton
Add mem::forget_unsized() for forgetting unsized values ~~Allows passing values of `T: ?Sized` types to `mem::drop` and `mem::forget`.~~ Adds `mem::forget_unsized()` that accepts `T: ?Sized`. I had to revert the PR that removed the `forget` intrinsic and replaced it with `ManuallyDrop`: https://github.com/rust-lang/rust/pull/40559 We can't use `ManuallyDrop::new()` here because it needs `T: Sized` and we don't have support for unsized return values yet (will we ever?). r? @eddyb
This commit is contained in:
commit
202724cddc
@ -717,6 +717,10 @@
|
||||
/// initialize memory previous set to the result of `uninit`.
|
||||
pub fn uninit<T>() -> T;
|
||||
|
||||
/// Moves a value out of scope without running drop glue.
|
||||
#[cfg(not(stage0))]
|
||||
pub fn forget<T: ?Sized>(_: T);
|
||||
|
||||
/// Reinterprets the bits of a value of one type as another type.
|
||||
///
|
||||
/// Both types must have the same size. Neither the original, nor the result,
|
||||
|
@ -106,6 +106,7 @@
|
||||
#![feature(staged_api)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(unsized_locals)]
|
||||
#![feature(untagged_unions)]
|
||||
#![feature(unwind_attributes)]
|
||||
#![feature(doc_alias)]
|
||||
|
@ -143,6 +143,19 @@ pub fn forget<T>(t: T) {
|
||||
ManuallyDrop::new(t);
|
||||
}
|
||||
|
||||
/// Like [`forget`], but also accepts unsized values.
|
||||
///
|
||||
/// This function is just a shim intended to be removed when the `unsized_locals` feature gets
|
||||
/// stabilized.
|
||||
///
|
||||
/// [`forget`]: fn.forget.html
|
||||
#[inline]
|
||||
#[cfg(not(stage0))]
|
||||
#[unstable(feature = "forget_unsized", issue = "0")]
|
||||
pub fn forget_unsized<T: ?Sized>(t: T) {
|
||||
unsafe { intrinsics::forget(t) }
|
||||
}
|
||||
|
||||
/// Returns the size of a type in bytes.
|
||||
///
|
||||
/// More specifically, this is the offset in bytes between successive elements
|
||||
|
@ -194,7 +194,7 @@ pub fn codegen_intrinsic_call(
|
||||
return;
|
||||
}
|
||||
// Effectively no-ops
|
||||
"uninit" => {
|
||||
"uninit" | "forget" => {
|
||||
return;
|
||||
}
|
||||
"needs_drop" => {
|
||||
|
@ -134,6 +134,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
"rustc_peek" => (1, vec![param(0)], param(0)),
|
||||
"init" => (1, Vec::new(), param(0)),
|
||||
"uninit" => (1, Vec::new(), param(0)),
|
||||
"forget" => (1, vec![param(0)], tcx.mk_unit()),
|
||||
"transmute" => (2, vec![ param(0) ], param(1)),
|
||||
"move_val_init" => {
|
||||
(1,
|
||||
|
Loading…
Reference in New Issue
Block a user