Skip to content

Commit 729ccbc

Browse files
committed
test track_caller on trait objects
1 parent 55bdb31 commit 729ccbc

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/run-pass/track-caller-attribute.rs

+23
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,28 @@ fn test_fn_ptr() {
3535
pass_to_ptr_call(tracked_unit, ());
3636
}
3737

38+
fn test_trait_obj() {
39+
trait Tracked {
40+
#[track_caller]
41+
fn handle(&self) { // `fn` here is what the `location` should point at.
42+
let location = std::panic::Location::caller();
43+
assert_eq!(location.file(), file!());
44+
// we only call this via trait object, so the def site should *always* be returned
45+
assert_eq!(location.line(), line!() - 4);
46+
assert_eq!(location.column(), 9);
47+
}
48+
}
49+
50+
impl Tracked for () {}
51+
impl Tracked for u8 {}
52+
53+
let tracked: &dyn Tracked = &5u8;
54+
tracked.handle();
55+
56+
const TRACKED: &dyn Tracked = &();
57+
TRACKED.handle();
58+
}
59+
3860
fn main() {
3961
let location = Location::caller();
4062
let expected_line = line!() - 1;
@@ -73,4 +95,5 @@ fn main() {
7395
assert_eq!(intrinsic.column(), 21);
7496

7597
test_fn_ptr();
98+
test_trait_obj();
7699
}

0 commit comments

Comments
 (0)