Closed
Description
The current content of this page only talks about the drop order within a block, and gives an example of code that does not compile in 2021 but does in 2024. However, the 2021 rules allow temporaries to outlive the block into the enclosing expression, such as the String
in the following program:
// compiles in 2021; fails in 2024
fn foo() {
{
&mut String::new()
}.push_str("hello");
}
This program cannot be fixed merely by reordering or introducing variables within the affected block. This case should be documented in order to help users with situations such as rust-lang/rust#134003.
@rustbot label Edition-2024