{
  "id": "rust/e0308-mismatched-types-expected-i32-found-u32",
  "signature": "error[E0308]: mismatched types -- expected `i32`, found `u32`",
  "signature_zh": "错误[E0308]：类型不匹配——期望`i32`，但找到`u32`",
  "regex": "error\\[E0308\\]: mismatched types -- expected `[a-zA-Z_][a-zA-Z0-9_]*`, found `[a-zA-Z_][a-zA-Z0-9_]*`",
  "domain": "rust",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "A value of one integer type is used where a different integer type is expected, due to Rust's strict type system not allowing implicit conversions.",
  "root_cause_type": "generic",
  "root_cause_zh": "由于Rust严格的类型系统不允许隐式转换，在期望一种整数类型的地方使用了另一种整数类型。",
  "versions": [
    {
      "version": "rustc 1.60.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "rustc 1.65.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "rustc 1.70.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "`as` cast can silently truncate or wrap, leading to data loss; it's not a clean conversion.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "If the source value is inherently u32 (e.g., from an API), changing the variable type may cause other mismatches.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Unsafe coercion is dangerous and undefined behavior; it doesn't solve the type mismatch.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use explicit conversion with `From` or `TryFrom` traits, e.g., `i32::try_from(u32_val)` and handle the Result.",
      "success_rate": 0.95,
      "how": "Use explicit conversion with `From` or `TryFrom` traits, e.g., `i32::try_from(u32_val)` and handle the Result.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the value is guaranteed to fit, use `as` cast with a comment explaining safety.",
      "success_rate": 0.9,
      "how": "If the value is guaranteed to fit, use `as` cast with a comment explaining safety.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "使用`From`或`TryFrom`特征进行显式转换，例如`i32::try_from(u32_val)`并处理Result。",
    "如果值保证在范围内，使用`as`强制转换并添加注释说明安全性。"
  ],
  "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.9,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-04-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}