Implicitly borrow all but the last usage of a variable

When a variable is used in multiple distinct expressions, then only the last one is able to move.

The compiler would reduce boilerplate, by implicitly borrowing every usage other than the last one.


  • Mutable borrows carry security implications. Don't implicitly borrow mutably.
  • Some trivial loops may unroll into a recurring routine vs. final iteration routine, with implicit borrowing for the recurring routine. But the compiler may not always know whether an iteration is the final iteration. Generally, the compiler could treat variable use in loops as implicit borrows.

What if you want to move a variable into a function such that it can't be used later?

1 Like

Implicit reborrowing, match ergonomics, etc. are already confusing enough as it is. Moreover, how could this be made compatible with generic functions? For instance, std::fs::read takes an impl AsRef<Path> IIRC. What should happen when you pass a String?

1 Like