# error[E0596]: cannot borrow data in a dereference of `*const T` as mutable

- **ID:** `rust/e0596-cannot-borrow-data-in-a-dereference-of-raw-pointer`
- **Domain:** rust
- **Category:** type_error
- **Error Code:** `E0596`
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

Attempting to mutate data through a raw const pointer (*const T), which is immutable by definition.

## Version Compatibility

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

## Workarounds

1. **Change the pointer type to *mut T at the definition site. Example: let ptr: *mut T = &mut value as *mut T;** (95% success)
   ```
   Change the pointer type to *mut T at the definition site. Example: let ptr: *mut T = &mut value as *mut T;
   ```
2. **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;** (80% success)
   ```
   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;
   ```
3. **Refactor to use Cell or RefCell for interior mutability, avoiding raw pointers entirely. Example: let cell = Cell::new(42);** (90% success)
   ```
   Refactor to use Cell or RefCell for interior mutability, avoiding raw pointers entirely. Example: let cell = Cell::new(42);
   ```

## Dead Ends

- **** — 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. (70% fail)
- **** — The compiler correctly rejects this because *const T doesn't guarantee mutability. You need *mut T explicitly. (90% fail)
- **** — This changes the API contract; callers with *const T will no longer compile without a cast. (40% fail)
