Skip to content
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

2024 No migration for tail expression temporary drop #132814

Closed
ehuss opened this issue Nov 9, 2024 · 4 comments
Closed

2024 No migration for tail expression temporary drop #132814

ehuss opened this issue Nov 9, 2024 · 4 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-edition-2024 Area: The 2024 edition C-bug Category: This is a bug. D-edition Diagnostics: An error or lint that should account for edition differences. L-tail_expr_drop_order Lint: tail_expr_drop_order T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ehuss
Copy link
Contributor

ehuss commented Nov 9, 2024

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
@ehuss ehuss added A-edition-2024 Area: The 2024 edition C-bug Category: This is a bug. D-edition Diagnostics: An error or lint that should account for edition differences. labels Nov 9, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 9, 2024
@jieyouxu jieyouxu added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 9, 2024
@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 9, 2024
@traviscross
Copy link
Contributor

cc @dingxiangfei2009

Minimized a bit further:

#![warn(rust_2024_compatibility)]
fn f() {}
fn g(_: &()) {}
fn main() {
    g({ &f() });
}

@dingxiangfei2009
Copy link
Contributor

@rustbot claim

@traviscross
Copy link
Contributor

@traviscross
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-edition-2024 Area: The 2024 edition C-bug Category: This is a bug. D-edition Diagnostics: An error or lint that should account for edition differences. L-tail_expr_drop_order Lint: tail_expr_drop_order T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants