{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreigh3fqbn7ezxxnirz7gixm5qozrbllodb4lmrzbcrvhbqc4hqd3u4",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mlehq6rg2ra2"
  },
  "path": "/t/type-inference-breaks-when-a-loop-is-added-between-inference-points/24232#post_1",
  "publishedAt": "2026-05-08T17:58:32.000Z",
  "site": "https://internals.rust-lang.org",
  "tags": [
    "Here is the playground link.",
    "Here is the GitHub issue link"
  ],
  "textContent": "Hello,\n\nI just noticed that the **compiler / Rust Analyzer** seems to behave strangely. It can no longer correctly infer types when there is a loop between the expression and the target type, as if the presence of loops causes it to lose track of the type inference context.\n\nI will provide the steps to reproduce the bug. (**The playground link can be found at the bottom**)\n\nTest struct :\n\n\n    #[derive(Clone, Debug)]\n    pub struct NodeMoonStatsDTO {\n        pub node_id: String,\n        pub uptime: u64,\n        //.....\n    }\n\n    type SharedState = Arc<DashMap<String, DashMap<String, NodeMoonStatsDTO>>>;\n\n    pub struct SystemMonitorService {\n        pub live_nodes_moon_stats: SharedState,\n       //.....\n    }\n\n\n**Step 1:** Type inference works correctly; `result` is properly inferred as `Option<Vec<NodeMoonStatsDTO>>`.\n\nHere are the details of the variable types :\n\n**Step 2:** Add the first building block before the bug appears.\n\nSo far, everything works correctly; no bug appears.\n\n**Step 3:** Introduce a loop.\n\nHowever, it correctly knows that `n` is of type `NodeMoonStatsDTO`, yet at the same time it seems to ignore it.\n\nThis is only one example; I have encountered the same issue in several parts of the code.\n\n**Here is an example code with the same bug (I replaced`DashMap` with `HashMap` to simplify it).**\n\nHere is the playground link.\n\nHere is the GitHub issue link\n\n* * *\n\nI use :\n\n\n    rustup: 1.29.0\n    rustc : 1.95.0\n    rust-analyzer: 0.3.2887\n\n\nThank you in advance for your help and feedback.",
  "title": "Type inference breaks when a loop is added between inference points"
}