# Should drop glue use #\[track\_caller\]?

**URL:** <https://internals.rust-lang.org/t/should-drop-glue-use-track-caller/13682>\
**Category:** Uncategorized\
**Created:** [December 27, 2020, 6:16pm UTC](https://internals.rust-lang.org/t/should-drop-glue-use-track-caller/13682 "2020-12-27T18:16:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ExpHP](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/exphp/32/6208_2.png) [@ExpHP](https://internals.rust-lang.org/u/ExpHP)\
**Post date:** [December 27, 2020, 6:16pm UTC](https://internals.rust-lang.org/t/should-drop-glue-use-track-caller/13682/1 "2020-12-27T18:16:18Z")

</div>

rustc nightly 2020-12-22 and stable 1.48.0

[Playground link](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c2f1f2eba0eb8a891458ab92f571ad39)

```rust
struct Bomb;

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

fn main() {
    Bomb;
}

```

```rust
    Finished dev [unoptimized + debuginfo] target(s) in 1.15s
     Running `target/debug/playground`
thread 'main' panicked at 'bomb dropped!', /rustc/bb1fbbf84455fbad9afd26c17e0f725019322655/library/core/src/ptr/mod.rs:179:1
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

```

The location in this panic isn't very useful. (Ideally one would like to see a line in `fn main`). I wonder if `core::ptr::drop_in_place` should be annotated as `#[track_caller]`? Are there any downsides to this?

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bjorn3/32/2736_2.png) [@bjorn3](https://internals.rust-lang.org/u/bjorn3)\
**Post date:** [December 27, 2020, 9:05pm UTC](https://internals.rust-lang.org/t/should-drop-glue-use-track-caller/13682/2 "2020-12-27T21:05:19Z")

</div>

Marking `drop_in_place` as `#[track_caller]` would have a severe negative impact on binary size and likely a non-neglectable decrease in runtime performance due to every implicit drop now having an `&'static Location` associated to it (huge size increase) that is passed to `drop_in_place` (increased register pressure)

---

<div class="post-metadata">

**Author:** ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)\
**Post date:** [December 27, 2020, 11:12pm UTC](https://internals.rust-lang.org/t/should-drop-glue-use-track-caller/13682/3 "2020-12-27T23:12:53Z")

</div>

In theory, since nearly all `Drop::drop` functions are not `#[track_caller]`, that extra unused argument would be optimized out. But that's putting a lot on optimization and would at best have a noticable negative impact on compile time.

---

<div class="post-metadata">

**Author:** ![skade](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/skade/32/3333_2.png) [@skade](https://internals.rust-lang.org/u/skade)\
**Post date:** [December 29, 2020, 10:35pm UTC](https://internals.rust-lang.org/t/should-drop-glue-use-track-caller/13682/4 "2020-12-29T22:35:16Z")

</div>

Given that drop bombs should _never_ happen (and are often off in release mode) and are single use, what speaks against a more sophisticated drop bomb that always prints the stack and useful debug info when active?

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 29, 2021, 10:35pm UTC](https://internals.rust-lang.org/t/should-drop-glue-use-track-caller/13682/5 "2021-03-29T22:35:21Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
