Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kpreid opened this issue Dec 7, 2024 · 3 comments · Fixed by #345
Labels
Edition-2024 Edition 2024

Comments

@kpreid
Copy link

kpreid commented Dec 7, 2024

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

@rustbot
Copy link
Collaborator

rustbot commented Dec 7, 2024

Error: Label Edition-2024 can only be set by Rust team members

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

@ehuss
Copy link
Contributor

ehuss commented Dec 9, 2024

Thanks for the report! Yea, the chapter was pretty light and definitely could use some expansion. I have posted #345 to try to address this. There's probably still more that can be said, but it's a bit of a tricky topic to describe succinctly.

@kpreid
Copy link
Author

kpreid commented Dec 10, 2024

Thanks for looking at this, @ehuss. Should this issue be labeled Edition-2024 for the record? I tried to do that but wasn't allowed. Could you do so if it is appropriate?

@ehuss ehuss added the Edition-2024 Edition 2024 label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Edition-2024 Edition 2024
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants