{
  "id": "rust/e0509-cannot-move-out-of-type-which-implements-drop",
  "signature": "error[E0509]: cannot move out of type `X`, which implements the `Drop` trait",
  "signature_zh": "错误[E0509]: 无法移出实现了 `Drop` trait 的类型 `X`",
  "regex": "error\\[E0509\\]: cannot move out of type `[^`]+`, which implements the `Drop` trait",
  "domain": "rust",
  "category": "type_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "试图移出实现了 Drop trait 的结构体或枚举的字段，这会导致在 drop 运行时类型处于无效状态。",
  "versions": [
    {
      "version": "rustc 1.70.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "rustc 1.75.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "rustc 1.80.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Clone creates a copy, but the original field is still moved, causing the same error. The Drop trait prevents partial moves.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Replacing the whole struct still requires moving the original struct, which is prevented by the Drop trait.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "You cannot convert a field type without moving it first, which is the original problem. The Drop trait blocks any partial move.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "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()",
      "success_rate": 0.9,
      "how": "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()",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use std::mem::ManuallyDrop to wrap the struct, then manually drop it after moving fields. Example: ManuallyDrop::new(my_struct).field",
      "success_rate": 0.85,
      "how": "Use std::mem::ManuallyDrop to wrap the struct, then manually drop it after moving fields. Example: ManuallyDrop::new(my_struct).field",
      "condition": "",
      "sources": []
    },
    {
      "action": "Implement Clone for the field type and clone it before moving, then keep the original struct intact. Example: let cloned = self.field.clone();",
      "success_rate": 0.75,
      "how": "Implement Clone for the field type and clone it before moving, then keep the original struct intact. Example: let cloned = self.field.clone();",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "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()",
    "Use std::mem::ManuallyDrop to wrap the struct, then manually drop it after moving fields. Example: ManuallyDrop::new(my_struct).field",
    "Implement Clone for the field type and clone it before moving, then keep the original struct intact. Example: let cloned = self.field.clone();"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://doc.rust-lang.org/error_codes/E0509.html",
  "official_doc_section": null,
  "error_code": "E0509",
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-06-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}