I’m confused. There are two almost identical examples. http://is.gd/4crvBD
Compiler will generate an error if variable type is added into map function (see second example). Why?
Compiler error E0495 is not found on Rust errors page Rust errors page. Why?
The key is your “almost” here. They’re not exactly the same. All references have a lifetime, but sometimes, they can be elided. So the actual type is
&'a String, but the question is, what
'a? There are a few different options here, and when it’s inferred, it picks the right one. But there’s no syntax for writing lifetimes in a closure like this, and when you write just
&String, it infers the wrong one.
So, the only solution here is to rely on the inference.
We have to actually write text for each error, and this is one of the ones that doesn’t have an example yet.
All references have a lifetime and if i can’t use it, may be is it a bug?
Every variable has a type, and i want to see it. I don’t want to rely on the inference.