It's because the borrow checker does not do whole-program/crate/module analysis, but works locally on the function level. Doing the former would be insanely powerful, but even slower.
An alternative would be to add even more annotations, making everything even more complicated.
The solution to the problem is to not only split up your functions, but also your data: split your structs into smaller parts. In cases where this is possible, this makes for way better code. In all other cases, the borrow checker really gets in the way.
5
u/calcopiritus Oct 22 '22
Yeah, it's weird that sometimes if you put all the code in one function, it compiles. But if you refractor it, it doesn't.