{
  "id": "rust/e0597-borrowed-value-from-iterator",
  "signature": "error[E0597]: borrowed value does not live long enough\n\nnote: argument requires that `value` is borrowed for `'static`",
  "signature_zh": "错误[E0597]：借用的值存活时间不够长\n\n注意：参数要求 `value` 被借用为 `'static` 生命周期",
  "regex": "borrowed value does not live long enough.*value.*borrowed for.*static",
  "domain": "rust",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Returning a reference to a local variable created inside a function or closure, often from an iterator chain like `.filter()` or `.map()`.",
  "root_cause_type": "generic",
  "root_cause_zh": "返回对在函数或闭包内部创建的局部变量的引用，通常来自迭代器链如 `.filter()` 或 `.map()`。",
  "versions": [
    {
      "version": "rustc 1.76",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "rustc 1.77",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The data still doesn't live long enough; the lifetime bound is a promise the compiler enforces, not a magic fix.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Can cause dangling pointers and undefined behavior; highly discouraged.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Clone or own the data instead of borrowing: `let cloned = value.clone();` or collect into a `Vec` before returning.",
      "success_rate": 0.9,
      "how": "Clone or own the data instead of borrowing: `let cloned = value.clone();` or collect into a `Vec` before returning.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Restructure the code to pass ownership: change function signature to return an owned type like `String` instead of `&str`.",
      "success_rate": 0.85,
      "how": "Restructure the code to pass ownership: change function signature to return an owned type like `String` instead of `&str`.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "克隆或拥有数据而不是借用：`let cloned = value.clone();` 或在返回前收集到 `Vec` 中。",
    "重构代码以传递所有权：将函数签名改为返回拥有类型如 `String` 而不是 `&str`。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://doc.rust-lang.org/stable/error_codes/E0597.html",
  "official_doc_section": null,
  "error_code": "E0597",
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.87,
  "resolvable": "true",
  "first_seen": "2023-09-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}