rust-lang / reference

The Rust Reference
https://doc.rust-lang.org/nightly/reference/
Apache License 2.0
1.25k stars 491 forks source link

list of place expressions is incomplete #1645

Open lolbinarycat opened 1 month ago

lolbinarycat commented 1 month ago

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.

ehuss commented 1 month ago

Can you please explain why it seems like control flow expressions are place expressions?

chorman0773 commented 1 month ago

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b6ab9f2513e411fc96a792bea657b20e shows what is happening here with errors:

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)

lolbinarycat commented 1 month ago

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.