# 错误[E0716]: 临时值在被借用时被丢弃

- **ID:** `rust/e0716-temporary-value-dropped`
- **领域:** rust
- **类别:** type_error
- **错误码:** `E0716`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

创建了一个临时值（例如来自函数调用）并获取了它的引用，但临时值在语句结束时被丢弃，而引用却存活更久。

## 版本兼容性

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

## 解决方案

1. ```
   Bind the temporary to a named variable with a lifetime that matches the reference. Example: 'let s = String::from("hello"); let r = &s;' instead of 'let r = &String::from("hello");'
   ```
2. ```
   Use 'let' with a longer scope: 'let x = foo(); let y = x.bar();' where 'bar' returns a reference.
   ```

## 无效尝试

- **** — Adding 'clone()' to the temporary without storing it in a variable — the clone still creates a temporary that is dropped. (70% 失败率)
- **** — Adding 'unsafe' block to extend lifetime — unsafe doesn't change lifetimes and is incorrect. (90% 失败率)
