{
  "id": "rust/e0277-the-trait-bound-stdmarkersync-is-not-satisfied",
  "signature": "error[E0277]: the trait bound `RefCell<i32>: std::marker::Sync` is not satisfied",
  "signature_zh": "错误[E0277]：未满足特征约束 `RefCell<i32>: std::marker::Sync`",
  "regex": "error\\[E0277\\]: the trait bound `.*std::marker::Sync` is not satisfied",
  "domain": "rust",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "RefCell provides interior mutability but is not Sync, so it cannot be shared across threads via Arc or static variables.",
  "root_cause_type": "generic",
  "root_cause_zh": "RefCell 提供了内部可变性，但不是 Sync 的，因此无法通过 Arc 或静态变量在线程间共享。",
  "versions": [
    {
      "version": "rustc 1.68.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "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"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Sync is a trait for safe shared access across threads, not related to cloning. Deriving Clone only enables cloning, not thread safety.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Arc provides shared ownership but does not make the inner type Sync. Mutex already provides Sync, so wrapping RefCell inside Mutex is unnecessary and the outer Arc doesn't help.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Marking RefCell as Sync is unsound because it allows data races. The compiler correctly prevents this.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Replace RefCell with Mutex: `let shared = Arc::new(Mutex::new(42));` then lock with `shared.lock().unwrap()`. Mutex is Sync and allows interior mutability safely across threads.",
      "success_rate": 0.95,
      "how": "Replace RefCell with Mutex: `let shared = Arc::new(Mutex::new(42));` then lock with `shared.lock().unwrap()`. Mutex is Sync and allows interior mutability safely across threads.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use atomic types for simple integers: `use std::sync::atomic::{AtomicI32, Ordering}; let shared = Arc::new(AtomicI32::new(42)); shared.store(100, Ordering::SeqCst);`",
      "success_rate": 0.9,
      "how": "Use atomic types for simple integers: `use std::sync::atomic::{AtomicI32, Ordering}; let shared = Arc::new(AtomicI32::new(42)); shared.store(100, Ordering::SeqCst);`",
      "condition": "",
      "sources": []
    },
    {
      "action": "If only single-threaded access is needed, use `Rc<RefCell<i32>>` instead of `Arc<RefCell<i32>>`.",
      "success_rate": 0.85,
      "how": "If only single-threaded access is needed, use `Rc<RefCell<i32>>` instead of `Arc<RefCell<i32>>`.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "将 RefCell 替换为 Mutex：`let shared = Arc::new(Mutex::new(42));` 然后使用 `shared.lock().unwrap()` 加锁。Mutex 是 Sync 的，可以跨线程安全地提供内部可变性。",
    "对于简单整数，使用原子类型：`use std::sync::atomic::{AtomicI32, Ordering}; let shared = Arc::new(AtomicI32::new(42)); shared.store(100, Ordering::SeqCst);`",
    "如果只需要单线程访问，使用 `Rc<RefCell<i32>>` 代替 `Arc<RefCell<i32>>`。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://doc.rust-lang.org/error_codes/E0277.html",
  "official_doc_section": null,
  "error_code": "E0277",
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-06-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}