Skip to content

dyn Trait by-value dispatch loses the #[track_caller] caller location #157964

Description

@kevin-valerio

by-value dyn dispatch reports the trait method line instead of the call site line. Location::caller() should report the obj.consume(line!()) call site but Location::caller() reports line 6 which is the trait method declaration. Compiled with the latest nightly on main

#![feature(unsized_fn_params)]
#![allow(internal_features)]

trait TrackedByValue {
    #[track_caller]
    fn consume(self, expected_line: u32);
}

impl TrackedByValue for u8 {
    fn consume(self, expected_line: u32) {
        let loc = std::panic::Location::caller();
        assert_eq!(loc.line(), expected_line);
    }
}

fn main() {
    let obj = Box::new(7_u8) as Box<dyn TrackedByValue>;
    obj.consume(line!());
}
$ rustc +nightly-2026-05-10 repro.rs -o repro
$ RUST_BACKTRACE=0 ./repro

thread 'main' (1214439) panicked at repro.rs:6:5:
assertion `left == right` failed
  left: 6
 right: 18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Fields

    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