{
  "id": "rust/e0716-temporary-value-dropped",
  "signature": "error[E0716]: temporary value dropped while borrowed",
  "signature_zh": "错误[E0716]: 临时值在被借用时被丢弃",
  "regex": "error\\[E0716\\]: temporary value dropped while borrowed",
  "domain": "rust",
  "category": "type_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "创建了一个临时值（例如来自函数调用）并获取了它的引用，但临时值在语句结束时被丢弃，而引用却存活更久。",
  "versions": [
    {
      "version": "1.65.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.72.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.80.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Adding 'clone()' to the temporary without storing it in a variable — the clone still creates a temporary that is dropped.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Adding 'unsafe' block to extend lifetime — unsafe doesn't change lifetimes and is incorrect.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "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\");'",
      "success_rate": 0.95,
      "how": "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\");'",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use 'let' with a longer scope: 'let x = foo(); let y = x.bar();' where 'bar' returns a reference.",
      "success_rate": 0.9,
      "how": "Use 'let' with a longer scope: 'let x = foo(); let y = x.bar();' where 'bar' returns a reference.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "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\");'",
    "Use 'let' with a longer scope: 'let x = foo(); let y = x.bar();' where 'bar' returns a reference."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://doc.rust-lang.org/stable/error_codes/E0716.html",
  "official_doc_section": null,
  "error_code": "E0716",
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2024-05-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}