Closed
Description
I think that if
and while
conditions should free any temporaries that occur within them (for while
conditions it's mandatory, actually, since the condition is evaluated many times).
That is, if I write:
if my_set().borrow().contains(&key) { ... }
the temporary returned by borrow()
should be freed once the condition is evaluated, before entering the body of the if
.
The same holds for whiles
.
What makes these expressions different from other compound forms is that the conditions are evaluated to scalar booleans, and hence can never create lasting aliases that might need to be preserved.
In the case of a while, this is needed because temporaries can never outlive conditional or repeated scopes, and the condition of a while is a repeated scope.