In theory, could the Rust compiler automatically infer lifetimes in every situation?

97 points lancejpollard

Reading about Rust Lifetimes, it says (bold added):

The patterns programmed into Rust’s analysis of references are called the lifetime elision rules. These aren’t rules for programmers to follow; they’re a set of particular cases that the compiler will consider, and if your code fits these cases, you don’t need to write the lifetimes explicitly.

The elision rules don’t provide full inference. If Rust deterministically applies the rules but there is still ambiguity as to what lifetimes the references have, the compiler won’t guess what the lifetime of the remaining references should be. In this case, instead of guessing, the compiler will give you an error that you can resolve by adding the lifetime annotations that specify how the references relate to each other.

Why doesn't the compiler guess? Could it guess? By that I mean, could it in theory guess and would it get it right every time? Why or why not? Why can't it automatically figure it out, what are the reasons it cannot?

Also, would be interesting to know when it can figure it out, what the specific elision rules are. Where can I find those described/listed?