Skip to content

2024 No migration for tail expression temporary drop #132814

Open
@ehuss

Description

I tried this code:

#![warn(rust_2024_compatibility)]

unsafe fn f() -> i32 {
    1
}

fn check(_: &i32) {}

fn main() {
    check(unsafe { &f() });
}

I expected to see this happen: Warning about the temporary being dropped too early. Or...I'm not fully understanding RFC 3606, and can't explain to myself why the temporary is not extended to the statement.

Instead, this happened: No warning, and this fails on 2024 with:

error[E0716]: temporary value dropped while borrowed
  --> src/main.rs:11:21
   |
11 |     check(unsafe { &f() });
   |     -----           ^^-
   |     |               | |
   |     |               | temporary value is freed at the end of this statement
   |     |               creates a temporary value which is freed while still in use
   |     borrow later used by call
   |
   = note: consider using a `let` binding to create a longer lived value

For more information about this error, try `rustc --explain E0716`.

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (b91a3a056 2024-11-07)
binary: rustc
commit-hash: b91a3a05609a46f73d23e0995ae7ebb4a4f429a5
commit-date: 2024-11-07
host: aarch64-apple-darwin
release: 1.84.0-nightly
LLVM version: 19.1.3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-edition-2024Area: The 2024 editionC-bugCategory: This is a bug.D-editionDiagnostics: An error or lint that should account for edition differences.L-tail_expr_drop_orderLint: tail_expr_drop_orderT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions