Skip to content

--quality-delta reports Drop::drop as dead code: the compiler calls it at scope end #494

Open

Description

@zom-2018

ripwire: 0.6.9 (Release, GNU 14.2.1)
Verb: --quality-delta

What happens

impl Drop for T { fn drop(&mut self) { … } } is called by the compiler when a T goes out of scope. No source line names drop, so the index has no edge to it, and the method is listed as dead code.

Minimal reproduction

W=$(mktemp -d) && mkdir -p "$W/src" && cd "$W" && git init -q .
printf '[package]\nname = "repro"\nversion = "0.1.0"\nedition = "2021"\n\n[dependencies]\n' > Cargo.toml
printf 'pub fn api() -> u32 {\n    2\n}\n' > src/lib.rs
git add -A && git -c user.name=r -c user.email=r@example.invalid commit -qm base
cat > src/lib.rs <<'RS'
pub fn api() -> u32 {
    use_guard()
}

struct Guard(u32);

impl Drop for Guard {
    fn drop(&mut self) {
        self.0 = 0;
    }
}

fn use_guard() -> u32 {
    let guard = Guard(3);
    guard.0
}
RS
cargo build
ripwire . --quality-delta --legend=compact

ripwire prints one row:

<r kind="dead-code" sym="src/lib.rs::Guard::drop" origin="new-symbol" p="src/lib.rs:8"/>

use_guard is not reported, because api calls it.

Control

A plain method that nobody calls would be reported, and it should be. The difference is that the caller of Drop::drop is implicit, and nothing in the index records it.

Why it matters

A guard type that cleans up in Drop is the usual way to make cleanup run on every exit path, including when a future is cancelled. The obvious workaround, an explicit cleanup call, does not run when the future is dropped mid-way. So the row cannot be fixed on the user side without a weaker design. It does not gate, but it shows up on every project that uses a cleanup guard.

Expected

drop in an impl Drop for … block counts as called, the way Python hooks and framework entry points are already excluded from --quality-delta's dead-code rows (PR #437, closing #228).

Activity

  1. zom-2018 commented on Nov 1, 2026

    @zom-2018
    Author

    Fix in #500. It exempts a Rust drop method, which the compiler runs at scope exit, through a Rust-only LangFacts column, and adds section 2b to test/qddialscheck.sh. The arm is red on main and green on the branch.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions