@@ -38,23 +38,31 @@ fn test_fn_ptr() {
38
38
fn test_trait_obj ( ) {
39
39
trait Tracked {
40
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 ) ;
41
+ fn handle ( & self ) -> & ' static Location < ' static > {
42
+ std:: panic:: Location :: caller ( )
47
43
}
48
44
}
49
45
50
46
impl Tracked for ( ) { }
51
47
impl Tracked for u8 { }
52
48
49
+ // Test that we get the correct location
50
+ // even with a call through a trait object
51
+
53
52
let tracked: & dyn Tracked = & 5u8 ;
54
- tracked. handle ( ) ;
53
+ let location = tracked. handle ( ) ;
54
+ let expected_line = line ! ( ) - 1 ;
55
+ assert_eq ! ( location. file( ) , file!( ) ) ;
56
+ assert_eq ! ( location. line( ) , expected_line) ;
57
+ assert_eq ! ( location. column( ) , 28 ) ;
55
58
56
59
const TRACKED : & dyn Tracked = & ( ) ;
57
- TRACKED . handle ( ) ;
60
+ let location = TRACKED . handle ( ) ;
61
+ let expected_line = line ! ( ) - 1 ;
62
+ assert_eq ! ( location. file( ) , file!( ) ) ;
63
+ assert_eq ! ( location. line( ) , expected_line) ;
64
+ assert_eq ! ( location. column( ) , 28 ) ;
65
+
58
66
}
59
67
60
68
fn main ( ) {
0 commit comments