Pressure Scenario: E0382 Moved Value

2026-08-30 浏览 (1)

Pressure Scenario: E0382 Moved Value

Skill Under Test

m01-ownership

User Question

"Why am I getting E0382 error: use of moved value?"

Code Context

fn main() {
    let s = String::from("hello");
    let s2 = s;
    println!("{}", s);  // E0382
}

Expected Behavior

  • Explain move semantics (ownership transfer)
  • Show that String is not Copy
  • Provide fix options (clone, reference, restructure)
  • Quick reference table for ownership patterns
  • Reference to P.VAR.01, P.VAR.02 guidelines

Baseline Test (without skill)

Date: [To be filled]

Result:

  • Move semantics: [PASS/FAIL]
  • Not Copy explanation: [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:

  • Move semantics: [PASS/FAIL]
  • Not Copy explanation: [PASS/FAIL]
  • Fix options: [PASS/FAIL]
  • Quick reference: [PASS/FAIL]
  • Guidelines: [PASS/FAIL]

Notes: [To be filled after test]

Edge Cases

  1. "Why does i32 work but String doesn't?" → Should explain Copy trait
  2. "Can I just use unsafe to ignore this?" → Should discourage, explain risks
  3. "Is clone always the solution?" → Should explain performance implications

你可能感兴趣的文章

Pressure Scenario: E0597 Lifetime Too Short

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