diff --git a/tests/pass/track-caller-attribute.rs b/tests/pass/track-caller-attribute.rs index dd1e2f809ad..6694764a234 100644 --- a/tests/pass/track-caller-attribute.rs +++ b/tests/pass/track-caller-attribute.rs @@ -66,6 +66,27 @@ impl Tracked for u8 {} assert_eq!(location.column(), 28); } +fn test_trait_obj2() { + // track_caller on the impl but not the trait. + pub trait Foo { + fn foo(&self) -> &'static Location<'static>; + } + + struct Bar; + impl Foo for Bar { + #[track_caller] + fn foo(&self) -> &'static Location<'static> { + std::panic::Location::caller() + } + } + let expected_line = line!() - 4; // the `fn` signature above + + let f = &Bar as &dyn Foo; + let loc = f.foo(); // trait doesn't track, so we don't point at this call site + assert_eq!(loc.file(), file!()); + assert_eq!(loc.line(), expected_line); +} + fn main() { let location = Location::caller(); let expected_line = line!() - 1; @@ -105,4 +126,5 @@ fn main() { test_fn_ptr(); test_trait_obj(); + test_trait_obj2(); }