# 错误[E0594]：无法赋值给 `Arc` 中的数据

- **ID:** `rust/e0594-cannot-assign-to-data-in-an-arc`
- **领域:** rust
- **类别:** type_error
- **错误码:** `E0594`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

尝试在没有内部可变性（例如 `Mutex`、`RwLock` 或 `Cell`）的情况下修改 `Arc<T>` 背后的数据。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.65.0 | active | — | — |
| 1.68.0 | active | — | — |
| 1.72.0 | active | — | — |

## 解决方案

1. ```
   使用 `Arc<Mutex<T>>` 并在修改前加锁：`*arc.lock().unwrap() = new_value;`
   ```
2. ```
   对于简单的数值类型使用 `Arc<AtomicU32>` 和 `store` 方法。
   ```

## 无效尝试

- **Using `unsafe` to cast `Arc<T>` to a mutable reference via raw pointer** — Undefined behavior due to data races; violates Rust's safety guarantees. (95% 失败率)
- **Wrapping the entire `Arc` in a `RefCell` without thread safety** — `RefCell` is not `Sync`, so the `Arc<RefCell<T>>` cannot be shared across threads. (70% 失败率)
