{
  "id": "rust/e0261-use-of-undetermined-lifetime",
  "signature": "error[E0261]: use of undeclared lifetime name `'a`",
  "signature_zh": "错误[E0261]: 使用了未声明的生命周期名称 `'a`",
  "regex": "error\\[E0261\\]: use of undeclared lifetime name `'[a-zA-Z_][a-zA-Z0-9_]*`",
  "domain": "rust",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Referencing a lifetime parameter that hasn't been declared in the function, struct, or impl block signature.",
  "root_cause_type": "generic",
  "root_cause_zh": "引用了未在函数、结构体或 impl 块签名中声明的生命周期参数。",
  "versions": [
    {
      "version": "rustc 1.70.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "rustc 1.75.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "rustc 1.80.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "'static means the reference lives for the entire program, which is overly restrictive and may not match actual data lifetimes.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The compiler still needs a lifetime; removal often results in E0106 (missing lifetime specifier).",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Anonymous lifetimes don't always work for struct fields or function signatures where explicit lifetimes are required.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Declare the lifetime parameter in the function signature or struct definition. Example: fn foo<'a>(x: &'a str) -> &'a str",
      "success_rate": 0.95,
      "how": "Declare the lifetime parameter in the function signature or struct definition. Example: fn foo<'a>(x: &'a str) -> &'a str",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use the elided lifetime syntax by removing the explicit lifetime and letting the compiler infer it. Example: fn foo(x: &str) -> &str",
      "success_rate": 0.9,
      "how": "Use the elided lifetime syntax by removing the explicit lifetime and letting the compiler infer it. Example: fn foo(x: &str) -> &str",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the lifetime is needed in a struct, add it as a generic parameter. Example: struct Foo<'a> { x: &'a str }",
      "success_rate": 0.95,
      "how": "If the lifetime is needed in a struct, add it as a generic parameter. Example: struct Foo<'a> { x: &'a str }",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Declare the lifetime parameter in the function signature or struct definition. Example: fn foo<'a>(x: &'a str) -> &'a str",
    "Use the elided lifetime syntax by removing the explicit lifetime and letting the compiler infer it. Example: fn foo(x: &str) -> &str",
    "If the lifetime is needed in a struct, add it as a generic parameter. Example: struct Foo<'a> { x: &'a str }"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://doc.rust-lang.org/error_codes/E0261.html",
  "official_doc_section": null,
  "error_code": "E0261",
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-04-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}