reference
reference copied to clipboard
Section on temporary order unclear
Apart from lifetime extension, the temporary scope of an expression is the smallest scope that contains the expression and is for one of the following:
- The entire function body.
- A statement.
- The body of a
if
,while
orloop
expression. ...
https://doc.rust-lang.org/reference/destructors.html#temporary-scopes
I'm ... not really sure what "is for one of the following" means here? I can make an educated guess, but this section reads really weirdly. Perhaps it could be clarified?
cc @eddyb @oli-obk you probably know what this should say at a technical level
A relevant example for this is https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=08b6246faa0dea1ad815e1f6e6fd52b8
if PrintOnDrop("a").0 != "a" || PrintOnDrop("b").0 != "b" || PrintOnDrop("c").0 == "c" {
// body
}
// prints b c a
What's going on here, as far as I can tell, is that a
's scope gets "extended" twice, once to cover its lazy boolean expressions, and once to cover the if
. But the reference text as written is not sufficient to explain this