Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 963f08b

Browse files
committed
Auto merge of rust-lang#2418 - RalfJung:track, r=RalfJung
add more track_caller tests Suggested by `@eddyb`
2 parents cc6439d + 1787c73 commit 963f08b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/pass/track-caller-attribute.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,27 @@ fn test_trait_obj() {
6666
assert_eq!(location.column(), 28);
6767
}
6868

69+
fn test_trait_obj2() {
70+
// track_caller on the impl but not the trait.
71+
pub trait Foo {
72+
fn foo(&self) -> &'static Location<'static>;
73+
}
74+
75+
struct Bar;
76+
impl Foo for Bar {
77+
#[track_caller]
78+
fn foo(&self) -> &'static Location<'static> {
79+
std::panic::Location::caller()
80+
}
81+
}
82+
let expected_line = line!() - 4; // the `fn` signature above
83+
84+
let f = &Bar as &dyn Foo;
85+
let loc = f.foo(); // trait doesn't track, so we don't point at this call site
86+
assert_eq!(loc.file(), file!());
87+
assert_eq!(loc.line(), expected_line);
88+
}
89+
6990
fn main() {
7091
let location = Location::caller();
7192
let expected_line = line!() - 1;
@@ -105,4 +126,5 @@ fn main() {
105126

106127
test_fn_ptr();
107128
test_trait_obj();
129+
test_trait_obj2();
108130
}

0 commit comments

Comments
 (0)