core::ptr::drop_in_place - Rust
Description: API documentation for the Rust `drop_in_place` fn in crate `core`.
Keywords: rust, rustlang, rust-lang, drop_in_place

# Function core::ptr::drop_in_place 1.8.0 [−] [src]

    #[lang = "drop_in_place"]
    pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T)

Executes the destructor (if any) of the pointed-to value.

This has two use cases:

- It is required to use `drop_in_place` to drop unsized types like trait objects, because they can't be read out onto the stack and dropped normally.

- It is friendlier to the optimizer to do this over `ptr::read` when dropping manually allocated memory (e.g. when writing Box/Rc/Vec), as the compiler doesn't need to prove that it's sound to elide the copy.

# Safety

This has all the same safety problems as `ptr::read` with respect to invalid pointers, types, and double drops.

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
↑
  Move up in search results
↓
  Move down in search results
↹
  Switch tab
⏎
  Go to active search result
+ / -
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)