Skip to content

Commit 5e4be45

Browse files
committed
Auto merge of #1162 - RalfJung:track-fn-ptr, r=RalfJung
test track_caller with fn ptrs Looks like we already use `ReifyShim` the right way, let's just make sure we test that!
2 parents b5603ed + 9f6df67 commit 5e4be45

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,33 @@ macro_rules! caller_location_from_macro {
1919
() => (core::panic::Location::caller());
2020
}
2121

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+
2238
fn main() {
2339
let location = Location::caller();
40+
let expected_line = line!() - 1;
2441
assert_eq!(location.file(), file!());
25-
assert_eq!(location.line(), 23);
42+
assert_eq!(location.line(), expected_line);
2643
assert_eq!(location.column(), 20);
2744

2845
let tracked = tracked();
46+
let expected_line = line!() - 1;
2947
assert_eq!(tracked.file(), file!());
30-
assert_eq!(tracked.line(), 28);
48+
assert_eq!(tracked.line(), expected_line);
3149
assert_eq!(tracked.column(), 19);
3250

3351
let nested = nested_intrinsic();
@@ -43,12 +61,16 @@ fn main() {
4361
// `Location::caller()` in a macro should behave similarly to `file!` and `line!`,
4462
// i.e. point to where the macro was invoked, instead of the macro itself.
4563
let inmacro = caller_location_from_macro!();
64+
let expected_line = line!() - 1;
4665
assert_eq!(inmacro.file(), file!());
47-
assert_eq!(inmacro.line(), 45);
66+
assert_eq!(inmacro.line(), expected_line);
4867
assert_eq!(inmacro.column(), 19);
4968

5069
let intrinsic = core::intrinsics::caller_location();
70+
let expected_line = line!() - 1;
5171
assert_eq!(intrinsic.file(), file!());
52-
assert_eq!(intrinsic.line(), 50);
72+
assert_eq!(intrinsic.line(), expected_line);
5373
assert_eq!(intrinsic.column(), 21);
74+
75+
test_fn_ptr();
5476
}

0 commit comments

Comments
 (0)