{
  "id": "rust/e0596-cannot-borrow-data-in-a-dereference-of-raw-pointer",
  "signature": "error[E0596]: cannot borrow data in a dereference of `*const T` as mutable",
  "signature_zh": "错误[E0596]: 无法将 `*const T` 解引用中的数据借用为可变",
  "regex": "error\\[E0596\\]: cannot borrow data in a dereference of `\\*const [^`]+` as mutable",
  "domain": "rust",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Attempting to mutate data through a raw const pointer (*const T), which is immutable by definition.",
  "root_cause_type": "generic",
  "root_cause_zh": "试图通过原始常量指针 (*const T) 修改数据，而该指针本质上是不可变的。",
  "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": "The cast is allowed in unsafe code, but if the original memory is read-only (e.g., pointing to a static), mutation causes UB. The error is a safety warning.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The compiler correctly rejects this because *const T doesn't guarantee mutability. You need *mut T explicitly.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This changes the API contract; callers with *const T will no longer compile without a cast.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Change the pointer type to *mut T at the definition site. Example: let ptr: *mut T = &mut value as *mut T;",
      "success_rate": 0.95,
      "how": "Change the pointer type to *mut T at the definition site. Example: let ptr: *mut T = &mut value as *mut T;",
      "condition": "",
      "sources": []
    },
    {
      "action": "If you must keep *const T, use std::ptr::addr_of_mut! or cast to *mut T with a safety justification. Example: let mut_ptr = const_ptr as *mut T;",
      "success_rate": 0.8,
      "how": "If you must keep *const T, use std::ptr::addr_of_mut! or cast to *mut T with a safety justification. Example: let mut_ptr = const_ptr as *mut T;",
      "condition": "",
      "sources": []
    },
    {
      "action": "Refactor to use Cell or RefCell for interior mutability, avoiding raw pointers entirely. Example: let cell = Cell::new(42);",
      "success_rate": 0.9,
      "how": "Refactor to use Cell or RefCell for interior mutability, avoiding raw pointers entirely. Example: let cell = Cell::new(42);",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Change the pointer type to *mut T at the definition site. Example: let ptr: *mut T = &mut value as *mut T;",
    "If you must keep *const T, use std::ptr::addr_of_mut! or cast to *mut T with a safety justification. Example: let mut_ptr = const_ptr as *mut T;",
    "Refactor to use Cell or RefCell for interior mutability, avoiding raw pointers entirely. Example: let cell = Cell::new(42);"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://doc.rust-lang.org/error_codes/E0596.html",
  "official_doc_section": null,
  "error_code": "E0596",
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-09-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}