list of place expressions is incomplete
several control flow expressions are actually place expressions:
fn main() {
let arr = [10, 20];
let arr_ref = &loop { break arr[0]; };
dbg!(arr_ref);
}
i've tested if and loop, doubtless there are many more.
Can you please explain why it seems like control flow expressions are place expressions?
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b6ab9f2513e411fc96a792bea657b20e shows what is happening here with errors:
breakis a value expression context, so it converts the place expression to a value expression by copy or move - it works in the above becausei32isCopy, in the playground it errors because*xis not movable andStringis notCopyloopis a value expression but because& $exprtakes a place expression (and not specifically an assignee expression), the result is promoted to a temporary - this is allowed in example because temporary lifetime extension let's it live for the rest of the function, and errors in the playground because you can't return a reference to a temporary.
If loop{break $place} was a place expression, then the playground would compile (replace the loop {break *x} with a place-propagating expression like (*x) to demonstrate this)
yeah i see that. the actual problem is that the rules for temporary lifetime extension are obfuscated and incomprehensible.
and also that rust-analyzer doesn't catch these errors, leading me to believe they are valid.
I'm going to close as I believe this has been answered. Please let us know if something is overlooked.