External Publication
Visit Post

Type inference failure when accessing a value before its type is resolved

Rust Internals [Unofficial] May 9, 2026
Source

@jplatte It’s essentially the same phenomenon, but triggered in a different way.

@tczajka Your example is indeed much clearer.


Working case:

A has an unknown type → A = BB has a known type → compiles successfully

Failing case:

A has an unknown type → access A.fieldA = BB has a known type → type inference fails

Even though the IDE (e.g. Rust Analyzer) resolves the type correctly, the compiler still reports a type inference error.

It seems that type inference loses track of the type if the value from A is accessed or manipulated before it is assigned to B.

This would be a welcome improvement.

I revised the post title and content (as well as the GitHub issue) so that the problem is no longer described as being specific to loops, but rather presented in a more general way.

Discussion in the ATmosphere

Loading comments...