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
by-value dyn dispatch reports the trait method line instead of the call site line.
Location::caller()should report theobj.consume(line!())call site butLocation::caller()reports line6which is the trait method declaration. Compiled with the latest nightly on main