Skip to content

tail_expr_drop_order lint can mention internal __awaitee name #136206

Open
@kpreid

Description

@kpreid
Contributor

Code

#![warn(tail_expr_drop_order)]

async fn foo() -> bool {
    false
}

pub async fn bar() {
    while let true = foo().await {}
}

Current output

warning: relative drop order changing in Rust 2024
 --> src/lib.rs:8:28
  |
8 |     while let true = foo().await {}
  |                      ------^^^^^  - now the temporary value is dropped here, before the local variables in the block or statement
  |                      |     |
  |                      |     this value will be stored in a temporary; let us call it `#1`
  |                      |     up until Edition 2021 `#1` is dropped last but will be dropped earlier in Edition 2024
  |                      `__awaitee` calls a custom destructor
  |                      `__awaitee` will be dropped later as of Edition 2024
  |
  = warning: this changes meaning in Rust 2024
  = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
  = note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages

Desired output

Something else instead of “__awaitee”.

Rationale and extra context

Note that arguably the lint shouldn’t be firing at all because there are no other local variables, but that is just because the example is minimal; in the real cases, there were other local variables with significant Drops.

Rust Version

rustc 1.86.0-nightly (2f348cb7c 2025-01-27)
binary: rustc
commit-hash: 2f348cb7ce4063fa4eb40038e6ada3c5214717bd
commit-date: 2025-01-27
host: aarch64-apple-darwin
release: 1.86.0-nightly
LLVM version: 19.1.7

Anything else?

@rustbot label A-edition-2024

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Jan 28, 2025
kpreid

kpreid commented on Jan 28, 2025

@kpreid
ContributorAuthor

@rustbot label L-tail_expr_drop_order

compiler-errors

compiler-errors commented on Jan 28, 2025

@compiler-errors
Member

I regressed this in 197f6d8, which caused the compiler not look into opaques to prevent cycles.

I think we can special case futures and the __awaitee field here with some span desugaring logic.

added
I-edition-triagedIssue: This issue has been reviewed and triaged by the Edition team.
on Jan 28, 2025
added
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
on Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-edition-2024Area: The 2024 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.I-edition-triagedIssue: This issue has been reviewed and triaged by the Edition team.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

        Participants

        @kpreid@traviscross@compiler-errors@jieyouxu@rustbot

        Issue actions

          `tail_expr_drop_order` lint can mention internal `__awaitee` name · Issue #136206 · rust-lang/rust