@@ -19,15 +19,33 @@ macro_rules! caller_location_from_macro {
19
19
( ) => ( core:: panic:: Location :: caller( ) ) ;
20
20
}
21
21
22
+ fn test_fn_ptr ( ) {
23
+ fn pass_to_ptr_call < T > ( f : fn ( T ) , x : T ) {
24
+ f ( x) ;
25
+ }
26
+
27
+ #[ track_caller]
28
+ fn tracked_unit ( _: ( ) ) {
29
+ let expected_line = line ! ( ) - 1 ;
30
+ let location = std:: panic:: Location :: caller ( ) ;
31
+ assert_eq ! ( location. file( ) , file!( ) ) ;
32
+ assert_eq ! ( location. line( ) , expected_line, "call shims report location as fn definition" ) ;
33
+ }
34
+
35
+ pass_to_ptr_call ( tracked_unit, ( ) ) ;
36
+ }
37
+
22
38
fn main ( ) {
23
39
let location = Location :: caller ( ) ;
40
+ let expected_line = line ! ( ) - 1 ;
24
41
assert_eq ! ( location. file( ) , file!( ) ) ;
25
- assert_eq ! ( location. line( ) , 23 ) ;
42
+ assert_eq ! ( location. line( ) , expected_line ) ;
26
43
assert_eq ! ( location. column( ) , 20 ) ;
27
44
28
45
let tracked = tracked ( ) ;
46
+ let expected_line = line ! ( ) - 1 ;
29
47
assert_eq ! ( tracked. file( ) , file!( ) ) ;
30
- assert_eq ! ( tracked. line( ) , 28 ) ;
48
+ assert_eq ! ( tracked. line( ) , expected_line ) ;
31
49
assert_eq ! ( tracked. column( ) , 19 ) ;
32
50
33
51
let nested = nested_intrinsic ( ) ;
@@ -43,12 +61,16 @@ fn main() {
43
61
// `Location::caller()` in a macro should behave similarly to `file!` and `line!`,
44
62
// i.e. point to where the macro was invoked, instead of the macro itself.
45
63
let inmacro = caller_location_from_macro ! ( ) ;
64
+ let expected_line = line ! ( ) - 1 ;
46
65
assert_eq ! ( inmacro. file( ) , file!( ) ) ;
47
- assert_eq ! ( inmacro. line( ) , 45 ) ;
66
+ assert_eq ! ( inmacro. line( ) , expected_line ) ;
48
67
assert_eq ! ( inmacro. column( ) , 19 ) ;
49
68
50
69
let intrinsic = core:: intrinsics:: caller_location ( ) ;
70
+ let expected_line = line ! ( ) - 1 ;
51
71
assert_eq ! ( intrinsic. file( ) , file!( ) ) ;
52
- assert_eq ! ( intrinsic. line( ) , 50 ) ;
72
+ assert_eq ! ( intrinsic. line( ) , expected_line ) ;
53
73
assert_eq ! ( intrinsic. column( ) , 21 ) ;
74
+
75
+ test_fn_ptr ( ) ;
54
76
}
0 commit comments