# error[E0706]: thread-local variable cannot be borrowed across a yield point

- **ID:** `rust/e0706-thread-local-cannot-be-borrowed-across-yield`
- **Domain:** rust
- **Category:** type_error
- **Error Code:** `E0706`
- **Verification:** ai_generated
- **Fix Rate:** 78%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.75.0 | active | — | — |
| 1.77.0 | active | — | — |
| 1.79.0 | active | — | — |

## Workarounds

1. **Clone the thread-local value before the await point: `let val = THREAD_LOCAL.with(|v| v.clone());` then use `val` after await.** (82% success)
   ```
   Clone the thread-local value before the await point: `let val = THREAD_LOCAL.with(|v| v.clone());` then use `val` after await.
   ```
2. **Restructure code to avoid holding the borrow across await: use `let result = { THREAD_LOCAL.with(|v| v.do_something()) }; result.await`.** (75% success)
   ```
   Restructure code to avoid holding the borrow across await: use `let result = { THREAD_LOCAL.with(|v| v.do_something()) }; result.await`.
   ```

## Dead Ends

- **Wrapping the thread-local in `Rc` to extend lifetime** — `Rc` is not `Send`, so cannot be used across await points in async contexts. (85% fail)
- **Using `unsafe` to extend the borrow lifetime manually** — Undefined behavior; compiler may still reject or cause data races. (90% fail)
