{
  "id": "rust/e0706-thread-local-cannot-be-borrowed-across-yield",
  "signature": "error[E0706]: thread-local variable cannot be borrowed across a yield point",
  "signature_zh": "错误[E0706]：线程局部变量无法跨越 yield 点借用",
  "regex": "error\\[E0706\\]: thread-local variable cannot be borrowed across a yield point",
  "domain": "rust",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "A reference to a thread-local variable (e.g., `thread_local!`) is held across an `.await` point in async code, which is unsafe because the thread may change.",
  "root_cause_type": "generic",
  "root_cause_zh": "在异步代码中，对线程局部变量（例如 `thread_local!`）的引用跨越了 `.await` 点，这可能导致线程切换，因此不安全。",
  "versions": [
    {
      "version": "1.75.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.77.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.79.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Wrapping the thread-local in `Rc` to extend lifetime",
      "why_fails": "`Rc` is not `Send`, so cannot be used across await points in async contexts.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using `unsafe` to extend the borrow lifetime manually",
      "why_fails": "Undefined behavior; compiler may still reject or cause data races.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Clone the thread-local value before the await point: `let val = THREAD_LOCAL.with(|v| v.clone());` then use `val` after await.",
      "success_rate": 0.82,
      "how": "Clone the thread-local value before the await point: `let val = THREAD_LOCAL.with(|v| v.clone());` then use `val` after await.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Restructure code to avoid holding the borrow across await: use `let result = { THREAD_LOCAL.with(|v| v.do_something()) }; result.await`.",
      "success_rate": 0.75,
      "how": "Restructure code to avoid holding the borrow across await: use `let result = { THREAD_LOCAL.with(|v| v.do_something()) }; result.await`.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在 await 点之前克隆线程局部值：`let val = THREAD_LOCAL.with(|v| v.clone());` 然后在 await 后使用 `val`。",
    "重构代码以避免跨 await 持有借用：使用 `let result = { THREAD_LOCAL.with(|v| v.do_something()) }; result.await`。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://doc.rust-lang.org/error_codes/E0706.html",
  "official_doc_section": null,
  "error_code": "E0706",
  "verification_tier": "ai_generated",
  "confidence": 0.83,
  "fix_success_rate": 0.78,
  "resolvable": "partial",
  "first_seen": "2024-02-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}