I recently started the "Learn Rust With Entirely Too Many Linked Lists" tutorial, and things were progressing swimmingly. That is, until I tried to implement Iter. I got to the part where the tutorial has 2 errors related to not specifying lifetimes. In my case, using the implementation from the tutorial verbatim, I also got 2 type incompatible errors:
mismatched types
expected enum Option<&second::Node<_>>
found enum Option<&Box<second::Node<_>>>
This refers to this line of code:
Iter { next: self.head.map(|node| &node) }
Note that if I change the code to:
Iter { next: self.head.map(|node| &*node) }
The error goes away, though there's still an issue with lifetimes.
So, my question is whether the language specification/compiler have changed since the tutorial was written, in such a way that would lead to this difference in errors?
Edit: Or maybe this is something from rust-analyzer? I would have to test on a computer to see if RA generates additional error messages here.
Anyways, do note that the type mismatch error is real, and the too-many-linked-lists book chapter does in fact address that error, right as the next point of order after adding the lifetimes. Even if the compiler's error message itself was to change here, this wouldn't be a language change; just an upfront more complete&detailed description of the reasons your non-compiling program in fact is not compiling.
Thanks for the quick, thoughtful response.
I pasted an abbreviated version of my code into the playground, and it indeed only shows the 2 lifetime issues. However, using the rust-analyzer in VSCode or just cargo build from the terminal, I get the additional 2 errors. FWIW I'm running rusty v1.77.1
It's nice to know the tutorial discusses these errors later on.
Thanks for getting over my first bump in the road