# 错误[E0596]: 无法将 `*const T` 解引用中的数据借用为可变

- **ID:** `rust/e0596-cannot-borrow-data-in-a-dereference-of-raw-pointer`
- **领域:** rust
- **类别:** type_error
- **错误码:** `E0596`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

试图通过原始常量指针 (*const T) 修改数据，而该指针本质上是不可变的。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| rustc 1.70.0 | active | — | — |
| rustc 1.75.0 | active | — | — |
| rustc 1.80.0 | active | — | — |

## 解决方案

1. ```
   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;
   ```
3. ```
   Refactor to use Cell or RefCell for interior mutability, avoiding raw pointers entirely. Example: let cell = Cell::new(42);
   ```

## 无效尝试

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