Temporaries in operands

⚓ Rust    📅 2025-12-26    👤 surdeus    👁️ 1      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Temporaries in operands

Reference says:

Temporaries are also created to hold the result of operands to an expression while the other operands are evaluated. The temporaries are associated to the scope of the expression with that operand. Since the temporaries are moved from once the expression is evaluated, dropping them has no effect unless one of the operands to an expression breaks out of the expression, returns, or panics.

As i understand, every value expression in a place expression context, will lead to a temporary variable.
But expressions with multiple operands need to hold the value of each operand until all operands are evaluated, EVEN if it's operand is a value expression context.

So this text says temporaries are created in two situations: value in place context, and value in value context in expressions which have multiple operands. Places in place context do not need temporaries at all, even if they are in expressions with multiple operands.

Sorry for bad english

Am i correct?

5 posts - 2 participants

Read full topic

🏷️ Rust_feed