# error[E0716]: temporary value dropped while borrowed

- **ID:** `rust/e0716-temporary-value-dropped`
- **Domain:** rust
- **Category:** type_error
- **Error Code:** `E0716`
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Creating a temporary value (e.g., from a function call) and taking a reference to it, but the temporary is dropped at the end of the statement while the reference outlives it.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.65.0 | active | — | — |
| 1.72.0 | active | — | — |
| 1.80.0 | active | — | — |

## Workarounds

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");'** (95% success)
   ```
   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.** (90% success)
   ```
   Use 'let' with a longer scope: 'let x = foo(); let y = x.bar();' where 'bar' returns a reference.
   ```

## Dead Ends

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