@@ -38,23 +38,31 @@ fn test_fn_ptr() {
3838fn test_trait_obj ( ) {
3939 trait Tracked {
4040 #[ 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 ( )
4743 }
4844 }
4945
5046 impl Tracked for ( ) { }
5147 impl Tracked for u8 { }
5248
49+ // Test that we get the correct location
50+ // even with a call through a trait object
51+
5352 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 ) ;
5558
5659 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+
5866}
5967
6068fn main ( ) {
0 commit comments