Four Surprising Limitations of Rust's Borrow Checker
This article delves into four surprising limitations of Rust's borrow checker encountered even by experienced Rustaceans. The first limitation involves the borrow checker's inability to fully account for match and return statements, leading to redundant checks when working with HashMaps. The second limitation concerns asynchronous programming, where Rust currently lacks the ability to express certain asynchronous callback type signatures. The third centers around FnMut closures not allowing re-borrowing of captured variables, restricting access to mutable state in async operations. Finally, the Send checker's lack of control flow awareness results in some Futures that should be Send being incorrectly flagged as non-Send. The author illustrates these limitations and their challenges with concrete code examples and workarounds, advocating for improvements to Rust's type system to enhance developer productivity.