{
  "id": "rust/e0308-expected-usize-found-float",
  "signature": "error[E0308]: mismatched types: expected `usize`, found `f64`",
  "signature_zh": "错误[E0308]：类型不匹配：期望 `usize`，得到 `f64`",
  "regex": "error\\[E0308\\]: mismatched types: expected `usize`, found `f64`",
  "domain": "rust",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Assigning or passing a floating-point value where an unsigned integer index is required, often in array indexing or slice operations.",
  "root_cause_type": "generic",
  "root_cause_zh": "在需要无符号整数索引的位置（如数组索引或切片操作）使用了浮点数。",
  "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.82.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Truncation may cause logic errors; the compiler allows it but the behavior is undefined for negative or NaN values.",
      "fail_rate": 0.45,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Rust requires explicit conversion; this approach is syntactically invalid.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "If the value comes from a computation or input that yields f64, the type mismatch persists.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use `as usize` to convert f64 to usize, ensuring the value is non-negative and within range: `let index = value as usize;`",
      "success_rate": 0.85,
      "how": "Use `as usize` to convert f64 to usize, ensuring the value is non-negative and within range: `let index = value as usize;`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use `f64::round()` or `f64::floor()` before casting: `let index = value.round() as usize;`",
      "success_rate": 0.8,
      "how": "Use `f64::round()` or `f64::floor()` before casting: `let index = value.round() as usize;`",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the value is from user input or computation, parse or compute it as `usize` directly: `let index: usize = some_usize_source;`",
      "success_rate": 0.9,
      "how": "If the value is from user input or computation, parse or compute it as `usize` directly: `let index: usize = some_usize_source;`",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Use `as usize` to convert f64 to usize, ensuring the value is non-negative and within range: `let index = value as usize;`",
    "Use `f64::round()` or `f64::floor()` before casting: `let index = value.round() as usize;`",
    "If the value is from user input or computation, parse or compute it as `usize` directly: `let index: usize = some_usize_source;`"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://doc.rust-lang.org/error_codes/E0308.html",
  "official_doc_section": null,
  "error_code": "E0308",
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.92,
  "resolvable": "true",
  "first_seen": "2023-06-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}