Skip to content

Edition guide for 2024 tail expressions incorrectly imply it only affects drop order within a block, not outside it #342

Closed
@kpreid

Description

@kpreid

Location:
https://github.com/rust-lang/edition-guide/blob/4efbefa611258543294f77ee03643eb16800b399/src/rust-2024/temporary-tail-expr-scope.md

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions