# error[E0509]: cannot move out of type `X`, which implements the `Drop` trait

- **ID:** `rust/e0509-cannot-move-out-of-type-which-implements-drop`
- **Domain:** rust
- **Category:** type_error
- **Error Code:** `E0509`
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

Attempting to move a field out of a struct or enum that implements Drop, which would leave the type in an invalid state after drop runs.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| rustc 1.70.0 | active | — | — |
| rustc 1.75.0 | active | — | — |
| rustc 1.80.0 | active | — | — |

## Workarounds

1. **Refactor to store the field in an Option<T> so you can use .take() to move it out without partial struct moves. Example: self.field.take().unwrap()** (90% success)
   ```
   Refactor to store the field in an Option<T> so you can use .take() to move it out without partial struct moves. Example: self.field.take().unwrap()
   ```
2. **Use std::mem::ManuallyDrop to wrap the struct, then manually drop it after moving fields. Example: ManuallyDrop::new(my_struct).field** (85% success)
   ```
   Use std::mem::ManuallyDrop to wrap the struct, then manually drop it after moving fields. Example: ManuallyDrop::new(my_struct).field
   ```
3. **Implement Clone for the field type and clone it before moving, then keep the original struct intact. Example: let cloned = self.field.clone();** (75% success)
   ```
   Implement Clone for the field type and clone it before moving, then keep the original struct intact. Example: let cloned = self.field.clone();
   ```

## Dead Ends

- **** — Clone creates a copy, but the original field is still moved, causing the same error. The Drop trait prevents partial moves. (60% fail)
- **** — Replacing the whole struct still requires moving the original struct, which is prevented by the Drop trait. (80% fail)
- **** — You cannot convert a field type without moving it first, which is the original problem. The Drop trait blocks any partial move. (50% fail)
