Hello,
I noticed that the compiler / Rust Analyzer behaves unexpectedly. Type inference fails if a value is accessed before the point where its type is ultimately inferred, as if the inference context is lost.
I will provide the steps to reproduce the bug. (The playground link can be found at the bottom)
Test struct :
#[derive(Clone, Debug)]
pub struct NodeMoonStatsDTO {
pub node_id: String,
pub uptime: u64,
//.....
}
type SharedState = Arc<DashMap<String, DashMap<String, NodeMoonStatsDTO>>>;
pub struct SystemMonitorService {
pub live_nodes_moon_stats: SharedState,
//.....
}
Step 1:
Type inference works correctly; result is properly inferred as Option<Vec<NodeMoonStatsDTO>>.
Here are the details of the variable types :
Step 2: Add the first building block before the bug appears.
So far, everything works correctly; no bug appears.
Step 3: Introduce a loop. ![]()
However, it correctly knows that n is of type NodeMoonStatsDTO, yet at the same time it seems to ignore it.
This is only one example; I have encountered the same issue in several parts of the code.
Here is an example code with the same bug (I replaced DashMap with HashMap to simplify it).
I use :
rustup: 1.29.0
rustc : 1.95.0
rust-analyzer: 0.3.2887
Thank you in advance for your help and feedback.





