rust-lang / rust-lang/rust

False negative in edition 2024 migration lints where point of drop is reordered against other side-effects

Open
#155,010 8 comments 0 reactions 1 assignee View on GitHub

@dingxiangfei2009 is already working on this.

Since Apr 22, 2026.

A-edition-2024 A-rust-for-linux C-bug E-help-wanted I-edition-triaged L-false-negative T-compiler T-lang
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

#![warn(rust_2024_compatibility)]

unsafe extern "C" {
    safe fn foo();
    safe fn bar();
}

struct SignificantDrop {}

impl SignificantDrop {
    fn take(&mut self) -> Option<usize> {
        Some(1)
    }
}

impl Drop for SignificantDrop {
    #[inline(always)]
    fn drop(&mut self) {
        foo();
    }
}

#[unsafe(no_mangle)]
fn f() {
    if let Some(_x) = {SignificantDrop{}.take()} {
        bar();
    }
}

I expected to see this happen: lint fired because the drop and function call are going to be reordered.

Instead, this happened: no lints, but generated code are different. https://godbolt.org/z/Mvd4x5o5h

This is an example code recently encountered in Rust-for-Linux: https://lore.kernel.org/all/20260403-lockhold-v1-1-c332b56cd8ae@google.com/. We hoped that migration to 2024 would fix the issue (and it does) but surprising this does not cause the migration lint to fire, meaning that automated migration between 2021 to 2024 has a hole (as semantics are changed).

Meta

rustc --version --verbose:

rust version 1.94.1 (e408947bf 2026-03-25)

@rustbot label +L-false-negative +A-edition-2024 +A-rust-for-linux

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.