# Destructuring Droppable structs

**URL:** <https://internals.rust-lang.org/t/destructuring-droppable-structs/20993>\
**Category:** language design\
**Created:** [June 8, 2024, 10:36am UTC](https://internals.rust-lang.org/t/destructuring-droppable-structs/20993 "2024-06-08T10:36:14Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![dhm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/dhm/32/4879_2.png) [@dhm](https://internals.rust-lang.org/u/dhm)\
**Post date:** [June 11, 2024, 6:37pm UTC](https://internals.rust-lang.org/t/destructuring-droppable-structs/20993/16 "2024-06-11T18:37:42Z")

</div>

FWIW, it's already possible to define a helper macro for this task:

```rs
struct Point { x: i32, y: i32 }

impl Drop for Point {
    fn drop(&mut self) {
        unreachable!()
    }
}

let p = Point { x: 42, y: 27 };
destructuring_drop! {
    let Point {
        x: value,
        y: _,
    } = p;
}
assert_eq!(dbg!(value), 42);

```

By having the macro expand to the following `unsafe` code:

```rs
let (value, _) = match *ManuallyDrop::new(p) {
    Point { ref x, ref y } => unsafe {
        (
            <*const _>::read(x),
            <*const _>::read(y),
        )
    },
};

```

- 
### [Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4c52b11558e1a4a7e834a88994361203)

Having the hard error become a lint (I don't care about its default polarity) seems like a less cumbersome and with-better-diagnostics way to achieve the same 🙂

---

_[View the full topic](https://internals.rust-lang.org/t/destructuring-droppable-structs/20993)._
