Open lolbinarycat opened 1 month ago
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:
break
is a value expression context, so it converts the place expression to a value expression by copy or move - it works in the above because i32
is Copy
, in the playground it errors because *x
is not movable and String
is not Copy
loop
is a value expression but because & $expr
takes 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.
several control flow expressions are actually place expressions:
i've tested
if
andloop
, doubtless there are many more.