Skip to content

#[track_caller] does not work on fn drop #116942

Open
@SludgePhD

Description

@SludgePhD

Putting #[track_caller] on a fn drop implementation does not attribute the panic to the code that drops the value. Instead, some location in the standard library is blamed:

struct S;

impl Drop for S {
    #[track_caller]
    fn drop(&mut self) {
        panic!("panicking!");
    }
}

fn main() {
    let _variable = S;
}

Outputs:

thread 'main' panicked at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ptr/mod.rs:497:1:
panicking!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-panicArea: Panicking machineryC-enhancementCategory: An issue proposing an enhancement or a PR with one.F-track_caller`#![feature(track_caller)]`T-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

    Issue actions