Skip to content

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

@nbdd0121

Description

@nbdd0121

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-edition-2024Area: The 2024 editionA-rust-for-linuxRelevant for the Rust-for-Linux projectC-bugCategory: This is a bug.L-false-negativeLint: False negative (should have fired but didn't).T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions