Rust Compiler Development Question

I am currently reading the Rust Book and I encountered this passage in chapter 4.3 in an example about the difference of two code snippets that are, from a logical pov, the same (and safe, but the compiler refuses one:
"A future version of Rust may be smart enough to let it compile"
So now I'm asking myself: Is there anything like this in the works?
Thanks in advance

One feature that would give a way for that code to compile (after properly annotating the get_first function) are partial borrows. These have been discussed for a while, but no consensus on what the feature would actually look like has been reached, mostly due to requiring lot of annotations to be useful. See for example Partial borrowing (for fun and profit) · Issue #1215 · rust-lang/rfcs · GitHub RFC: Partial Types (v3) by VitWW · Pull Request #3736 · rust-lang/rfcs · GitHub Generalized Partial Borrows - #4 by danjl1100 - language design - Rust Internals

Another feature that would allow this to compile would be some sort of "see-through-functions" for the borrow checker. If this will ever be implemented it will probably only work for functions in the current crate/module and require an opt-in though. There are also chances this will worsen compile times, as the borrow checker will have to look at more code when checking a function.

3 Likes

Thx for your detailed answer!