Pressure Scenario: E0597 Lifetime Too Short

2026-08-30 浏览 (1)

Pressure Scenario: E0597 Lifetime Too Short

Skill Under Test

m01-ownership

User Question

"Why am I getting E0597: borrowed value does not live long enough?"

Code Context

fn get_str() -> &str {
    let s = String::from("hello");
    &s  // E0597
}

Expected Behavior

  • Explain stack vs heap lifetime
  • Show why returned reference is invalid
  • Provide fix options (return owned, 'static, lifetime params)
  • Quick reference for lifetime patterns
  • Reference to P.MEM.LFT.01, P.MEM.LFT.02 guidelines

Baseline Test (without skill)

Date: [To be filled]

Result:

  • Stack/heap lifetime: [PASS/FAIL]
  • Invalid reference: [PASS/FAIL]
  • Fix options: [PASS/FAIL]
  • Quick reference: [PASS/FAIL]
  • Guidelines: [PASS/FAIL]

Notes: [To be filled after test]

Post-Skill Test

Date: [To be filled]

Result:

  • Stack/heap lifetime: [PASS/FAIL]
  • Invalid reference: [PASS/FAIL]
  • Fix options: [PASS/FAIL]
  • Quick reference: [PASS/FAIL]
  • Guidelines: [PASS/FAIL]

Notes: [To be filled after test]

Edge Cases

  1. "What if I use Box?" → Should explain heap allocation
  2. "Can I use 'static?" → Should explain when appropriate
  3. "What about Cow?" → Should suggest for flexible ownership

你可能感兴趣的文章

Pressure Scenario: E0382 Moved Value

  • 所属分类: AI
  • 本文标签: rust
  • 版权声明: 本文链接 https://seaxiang.com/blog/6ZsgINnV