Why nested mut method calls aren't allowed

38 points ArtisticHamster

I have a factory type which has methods like create\_a, create\_b which are mut. When I have code like this:

let x = f.create_a(f.create_b())

Rust complains that I can't have a call while there's a mutable borrow of f. However, it doesn't complain about this:

let b = f.create_b();
let x = f.create_a(b)

Why it's implemented this way? I.e. allowing above, at first sight doesn't lead to any problems. What could I do to work around this problem and have nice code. Creating a large number of tmp vars isn't very nice thing, since it leads to overly verbose code.

P.S. It's the question about the reasons why the language is designed this way, but for those who want to play around with this, here's the playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ec1d5d1267142bc153fffad771af9fae