Hello all, I've been poking at @Gankra's excellent Learn Rust by writing Entirely Too Many linked lists and ran into a bug I can't get my head around.
I was following along and got to this code: Rust Playground
This throws the exception:
error[E0308]: mismatched types
--> src/lib.rs:95:22
|
95 | Ref::map(node.borrow(), |node| &node.elem)
| ^^^^^^^^^^^^^ expected struct `std::cell::Ref`, found reference
|
= note: expected type `std::cell::Ref<'_, _>`
found type `&_`
error[E0609]: no field `elem` on type `&_`
--> src/lib.rs:95:50
|
95 | Ref::map(node.borrow(), |node| &node.elem)
| ^^^^
error[E0308]: mismatched types
--> src/lib.rs:101:22
|
101 | Ref::map(node.borrow(), |node| &node.elem)
| ^^^^^^^^^^^^^ expected struct `std::cell::Ref`, found reference
|
= note: expected type `std::cell::Ref<'_, _>`
found type `&_`
error[E0609]: no field `elem` on type `&_`
--> src/lib.rs:101:50
|
101 | Ref::map(node.borrow(), |node| &node.elem)
| ^^^^
error: aborting due to 4 previous errors
Some errors occurred: E0308, E0609.
However if we remove the import line of use core::borrow::Borrow;
and change nothing else, it successfully compiles and runs: Rust Playground
What's going on with this import and why is it causing this error? Should importing Borrow
directly be avoided?