E0502 and encapsulated borrows

Hi,

I find the borrow checker has a strange behavior when borrows are encapsulated. For example the following code:

foo.fun0_with_imm_borrow(foo.fun1_with_mut_borrow());

is not accepted by the borrow checker, yet it is (should be?) equivalent to

let res = foo.fun1_with_mut_borrow();
foo.fun0_with_imm_borrow(res);

which does compile without problem.
Is there any reason behind this design?

Here is an example of the issue in the rust playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f682ebef4702a0ca5d3215e9dd3b632b

No, it's equivalent to below.

let callee = &foo;
let arg = foo.func1_with_mut_borrow();
Foo::func0_with_imm_borrow(callee, arg)

Method call syntax is a compiler assisted sugar for fully qualified function call, or UFCS(Univalsal Function Call Syntax). Check this chapter of the book for more details.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.